diff --git a/database/create-schema.sql b/database/create-schema.sql index 49df751..511f9c0 100644 --- a/database/create-schema.sql +++ b/database/create-schema.sql @@ -80,6 +80,35 @@ CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public; COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)'; +-- +-- Name: add_file_to_tag_recursive(uuid, uuid); Type: FUNCTION; Schema: data; Owner: - +-- + +CREATE FUNCTION data.add_file_to_tag_recursive(f_id uuid, t_id uuid) RETURNS SETOF uuid + LANGUAGE plpgsql + AS $$ +DECLARE + tmp uuid; + tt_id uuid; + ttt_id uuid; +BEGIN + INSERT INTO data.file_tag VALUES (f_id, t_id) ON CONFLICT DO NOTHING RETURNING tag_id INTO tmp; + IF tmp IS NULL THEN + RETURN; + END IF; + RETURN NEXT t_id; + FOR tt_id IN + SELECT a.add_tag_id FROM data.autotags a WHERE a.trigger_tag_id=t_id AND a.is_active + LOOP + FOR ttt_id IN SELECT data.add_file_to_tag_recursive(f_id, tt_id) + LOOP + RETURN NEXT ttt_id; + END LOOP; + END LOOP; +END; +$$; + + -- -- Name: uuid_extract_timestamp(uuid); Type: FUNCTION; Schema: public; Owner: - -- @@ -267,7 +296,7 @@ CREATE TABLE data.autotags ( CREATE TABLE data.categories ( id uuid DEFAULT public.uuid_v7() NOT NULL, name character varying(256) NOT NULL, - notes text, + notes text DEFAULT ''::text NOT NULL, color character(6), creator_id smallint NOT NULL );