--
-- PostgreSQL database dump
--

-- Dumped from database version 17.4 (Debian 17.4-1.pgdg120+2)
-- Dumped by pg_dump version 17.2

-- Started on 2025-03-08 21:37:57 CET

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET transaction_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- TOC entry 6 (class 2615 OID 2200)
-- Name: public; Type: SCHEMA; Schema: -; Owner: pg_database_owner
--

CREATE SCHEMA public;


ALTER SCHEMA public OWNER TO pg_database_owner;

--
-- TOC entry 3488 (class 0 OID 0)
-- Dependencies: 6
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: pg_database_owner
--

COMMENT ON SCHEMA public IS 'standard public schema';


--
-- TOC entry 239 (class 1255 OID 16392)
-- Name: delete_unused_tags(); Type: FUNCTION; Schema: public; Owner: f0ck
--

CREATE FUNCTION public.delete_unused_tags() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
begin
  delete from tags
  where
    tags.id not in (select tag_id from tags_assign) and
    tags.id = OLD.tag_id and
    tags.tag != 'sfw' and
    tags.tag != 'nsfw';
  return OLD;
end $$;


ALTER FUNCTION public.delete_unused_tags() OWNER TO f0ck;

--
-- TOC entry 240 (class 1255 OID 16393)
-- Name: fill_normalized(); Type: FUNCTION; Schema: public; Owner: f0ck
--

CREATE FUNCTION public.fill_normalized() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
begin
  NEW.normalized = slugify(NEW.tag);
  return NEW;
end$$;


ALTER FUNCTION public.fill_normalized() OWNER TO f0ck;

--
-- TOC entry 241 (class 1255 OID 16394)
-- Name: slugify(text); Type: FUNCTION; Schema: public; Owner: f0ck
--

CREATE FUNCTION public.slugify(v text) RETURNS text
    LANGUAGE plpgsql
    AS $$
BEGIN
  RETURN trim(BOTH '-' FROM regexp_replace(lower(unaccent(trim(v))), '[\u0000-\u002f \u003a-\u0040\u005b-\u0060\u007b-\u00bf]+', '', 'gi'));
END;
$$;


ALTER FUNCTION public.slugify(v text) OWNER TO f0ck;

--
-- TOC entry 242 (class 1255 OID 16395)
-- Name: unaccent_text(text); Type: FUNCTION; Schema: public; Owner: f0ck
--

CREATE FUNCTION public.unaccent_text(text) RETURNS text
    LANGUAGE sql IMMUTABLE COST 1
    AS $_$
  -- unaccent is STABLE, but the indexes must use IMMUTABLE functions.
  -- comment this line out when calling pg_dump.
  SELECT unaccent($1);

  -- Uncomment this line when calling pg_dump.
  --SELECT ''::text;
$_$;


ALTER FUNCTION public.unaccent_text(text) OWNER TO f0ck;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- TOC entry 218 (class 1259 OID 16396)
-- Name: favorites; Type: TABLE; Schema: public; Owner: f0ck
--

CREATE TABLE public.favorites (
    user_id integer NOT NULL,
    item_id integer NOT NULL
);


ALTER TABLE public.favorites OWNER TO f0ck;

--
-- TOC entry 219 (class 1259 OID 16399)
-- Name: items_id_seq; Type: SEQUENCE; Schema: public; Owner: f0ck
--

CREATE SEQUENCE public.items_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.items_id_seq OWNER TO f0ck;

--
-- TOC entry 220 (class 1259 OID 16400)
-- Name: items; Type: TABLE; Schema: public; Owner: f0ck
--

CREATE TABLE public.items (
    id integer DEFAULT nextval('public.items_id_seq'::regclass) NOT NULL,
    src character varying(255) NOT NULL,
    dest character varying(40) NOT NULL,
    mime character varying(100) NOT NULL,
    size integer NOT NULL,
    checksum character varying(255) NOT NULL,
    username character varying(40) NOT NULL,
    userchannel character varying(255) NOT NULL,
    usernetwork character varying(40) NOT NULL,
    stamp integer NOT NULL,
    active boolean NOT NULL,
    thumb character varying(100)
);


ALTER TABLE public.items OWNER TO f0ck;

--
-- TOC entry 3490 (class 0 OID 0)
-- Dependencies: 220
-- Name: COLUMN items.src; Type: COMMENT; Schema: public; Owner: f0ck
--

COMMENT ON COLUMN public.items.src IS 'src-Link';


--
-- TOC entry 3491 (class 0 OID 0)
-- Dependencies: 220
-- Name: COLUMN items.dest; Type: COMMENT; Schema: public; Owner: f0ck
--

COMMENT ON COLUMN public.items.dest IS 'filename';


--
-- TOC entry 221 (class 1259 OID 16406)
-- Name: items_li; Type: VIEW; Schema: public; Owner: f0ck
--

CREATE VIEW public.items_li AS
SELECT
    NULL::integer AS id,
    NULL::character varying(255) AS src,
    NULL::character varying(40) AS dest,
    NULL::character varying(100) AS mime,
    NULL::integer AS size,
    NULL::character varying(255) AS checksum,
    NULL::character varying(40) AS username,
    NULL::character varying(255) AS userchannel,
    NULL::character varying(40) AS usernetwork,
    NULL::integer AS stamp;


ALTER VIEW public.items_li OWNER TO f0ck;

--
-- TOC entry 222 (class 1259 OID 16410)
-- Name: tags_assign; Type: TABLE; Schema: public; Owner: f0ck
--

CREATE TABLE public.tags_assign (
    item_id integer NOT NULL,
    tag_id integer NOT NULL,
    user_id integer DEFAULT 10 NOT NULL
);


ALTER TABLE public.tags_assign OWNER TO f0ck;

--
-- TOC entry 223 (class 1259 OID 16414)
-- Name: tags_nsfp; Type: TABLE; Schema: public; Owner: f0ck
--

CREATE TABLE public.tags_nsfp (
    id integer NOT NULL
);


ALTER TABLE public.tags_nsfp OWNER TO f0ck;

--
-- TOC entry 224 (class 1259 OID 16417)
-- Name: items_sfw; Type: VIEW; Schema: public; Owner: f0ck
--

CREATE VIEW public.items_sfw AS
 SELECT ( SELECT
                CASE
                    WHEN (tags_assign.tag_id > 0) THEN tags_assign.tag_id
                    ELSE 0
                END AS "case"
           FROM public.tags_assign
          WHERE ((tags_assign.tag_id = ANY (ARRAY[1, 2])) AND (tags_assign.item_id = items.id))) AS sfw,
    ( SELECT
                CASE
                    WHEN (tags_assign.tag_id > 0) THEN 1
                    ELSE 0
                END AS "case"
           FROM public.tags_assign
          WHERE ((tags_assign.tag_id IN ( SELECT tags_nsfp.id
                   FROM public.tags_nsfp)) AND (tags_assign.item_id = items.id))
         LIMIT 1) AS nsfp,
    id,
    src,
    dest,
    mime,
    size,
    checksum,
    username,
    userchannel,
    usernetwork,
    stamp,
    active
   FROM public.items;


ALTER VIEW public.items_sfw OWNER TO f0ck;

--
-- TOC entry 225 (class 1259 OID 16422)
-- Name: tags_id_seq; Type: SEQUENCE; Schema: public; Owner: f0ck
--

CREATE SEQUENCE public.tags_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.tags_id_seq OWNER TO f0ck;

--
-- TOC entry 226 (class 1259 OID 16423)
-- Name: tags; Type: TABLE; Schema: public; Owner: f0ck
--

CREATE TABLE public.tags (
    id integer DEFAULT nextval('public.tags_id_seq'::regclass) NOT NULL,
    tag character varying(70) NOT NULL,
    normalized character varying(70) NOT NULL
);


ALTER TABLE public.tags OWNER TO f0ck;

--
-- TOC entry 227 (class 1259 OID 16427)
-- Name: user_id_seq; Type: SEQUENCE; Schema: public; Owner: f0ck
--

CREATE SEQUENCE public.user_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.user_id_seq OWNER TO f0ck;

--
-- TOC entry 228 (class 1259 OID 16428)
-- Name: user; Type: TABLE; Schema: public; Owner: f0ck
--

CREATE TABLE public."user" (
    id integer DEFAULT nextval('public.user_id_seq'::regclass) NOT NULL,
    login character varying(255) NOT NULL,
    "user" character varying(255) NOT NULL,
    password character varying(167) NOT NULL,
    admin boolean NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL
);


ALTER TABLE public."user" OWNER TO f0ck;

--
-- TOC entry 229 (class 1259 OID 16435)
-- Name: items_tags; Type: VIEW; Schema: public; Owner: f0ck
--

CREATE VIEW public.items_tags AS
 SELECT ( SELECT
                CASE
                    WHEN (tags_assign.tag_id > 0) THEN tags_assign.tag_id
                    ELSE 0
                END AS "case"
           FROM public.tags_assign
          WHERE ((tags_assign.tag_id = ANY (ARRAY[1, 2])) AND (tags_assign.item_id = items.id))) AS sfw,
    ( SELECT
                CASE
                    WHEN (tags_assign.tag_id > 0) THEN 1
                    ELSE 0
                END AS "case"
           FROM public.tags_assign
          WHERE ((tags_assign.tag_id IN ( SELECT tags_nsfp.id
                   FROM public.tags_nsfp)) AND (tags_assign.item_id = items.id))
         LIMIT 1) AS nsfp,
    ( SELECT jsonb_agg(jsonb_build_object('id', tags.id, 'normalized', tags.normalized)) AS jsonb_agg
           FROM (public.tags_assign
             LEFT JOIN public.tags ON ((tags.id = tags_assign.tag_id)))
          WHERE (tags_assign.item_id = items.id)) AS tags,
    ( SELECT jsonb_agg(jsonb_build_object('id', favorites.user_id, 'user', "user"."user")) AS jsonb_agg
           FROM (public.favorites
             LEFT JOIN public."user" ON (("user".id = favorites.user_id)))
          WHERE (favorites.item_id = items.id)) AS favs,
    id,
    src,
    dest,
    mime,
    size,
    checksum,
    username,
    userchannel,
    usernetwork,
    stamp,
    active
   FROM public.items;


ALTER VIEW public.items_tags OWNER TO f0ck;

--
-- TOC entry 230 (class 1259 OID 16440)
-- Name: tags_alias; Type: TABLE; Schema: public; Owner: f0ck
--

CREATE TABLE public.tags_alias (
    tag_orig_id integer NOT NULL,
    tag_alias character varying NOT NULL
);


ALTER TABLE public.tags_alias OWNER TO f0ck;

--
-- TOC entry 231 (class 1259 OID 16445)
-- Name: user_alias; Type: TABLE; Schema: public; Owner: f0ck
--

CREATE TABLE public.user_alias (
    userid integer NOT NULL,
    alias character varying(255) NOT NULL
);

ALTER TABLE ONLY public.user_alias REPLICA IDENTITY FULL;


ALTER TABLE public.user_alias OWNER TO f0ck;

--
-- TOC entry 232 (class 1259 OID 16448)
-- Name: user_options; Type: TABLE; Schema: public; Owner: f0ck
--

CREATE TABLE public.user_options (
    user_id integer NOT NULL,
    mode integer NOT NULL,
    theme character varying(50) NOT NULL,
    avatar integer,
    fullscreen smallint DEFAULT '0'::smallint NOT NULL
);


ALTER TABLE public.user_options OWNER TO f0ck;

--
-- TOC entry 233 (class 1259 OID 16453)
-- Name: user_sessions_id_seq; Type: SEQUENCE; Schema: public; Owner: f0ck
--

CREATE SEQUENCE public.user_sessions_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.user_sessions_id_seq OWNER TO f0ck;

--
-- TOC entry 234 (class 1259 OID 16454)
-- Name: user_sessions; Type: TABLE; Schema: public; Owner: f0ck
--

CREATE TABLE public.user_sessions (
    id integer DEFAULT nextval('public.user_sessions_id_seq'::regclass) NOT NULL,
    user_id integer NOT NULL,
    session character varying(32) NOT NULL,
    browser character varying(255) NOT NULL,
    created_at integer NOT NULL,
    last_used integer NOT NULL,
    kmsi smallint DEFAULT '0'::smallint NOT NULL
);


ALTER TABLE public.user_sessions OWNER TO f0ck;

--
-- TOC entry 3469 (class 0 OID 16396)
-- Dependencies: 218
-- Data for Name: favorites; Type: TABLE DATA; Schema: public; Owner: f0ck
--

COPY public.favorites (user_id, item_id) FROM stdin;
\.


--
-- TOC entry 3471 (class 0 OID 16400)
-- Dependencies: 220
-- Data for Name: items; Type: TABLE DATA; Schema: public; Owner: f0ck
--

COPY public.items (id, src, dest, mime, size, checksum, username, userchannel, usernetwork, stamp, active, thumb) FROM stdin;
\.


--
-- TOC entry 3475 (class 0 OID 16423)
-- Dependencies: 226
-- Data for Name: tags; Type: TABLE DATA; Schema: public; Owner: f0ck
--

COPY public.tags (id, tag, normalized) FROM stdin;
1	sfw	sfw
2	nsfw	nsfw
\.


--
-- TOC entry 3478 (class 0 OID 16440)
-- Dependencies: 230
-- Data for Name: tags_alias; Type: TABLE DATA; Schema: public; Owner: f0ck
--

COPY public.tags_alias (tag_orig_id, tag_alias) FROM stdin;
1	1
2	2
\.


--
-- TOC entry 3472 (class 0 OID 16410)
-- Dependencies: 222
-- Data for Name: tags_assign; Type: TABLE DATA; Schema: public; Owner: f0ck
--

COPY public.tags_assign (item_id, tag_id, user_id) FROM stdin;
\.


--
-- TOC entry 3473 (class 0 OID 16414)
-- Dependencies: 223
-- Data for Name: tags_nsfp; Type: TABLE DATA; Schema: public; Owner: f0ck
--

COPY public.tags_nsfp (id) FROM stdin;
\.


--
-- TOC entry 3477 (class 0 OID 16428)
-- Dependencies: 228
-- Data for Name: user; Type: TABLE DATA; Schema: public; Owner: f0ck
--

COPY public."user" (id, login, "user", password, admin, created_at) FROM stdin;
2	nixc	nixc	$f0ck$af70e2b4c9f50aa9c9355fc576440d33:4c8ad909502c32be64a9e6d86befd47542f037387ba6c56691b459c8ed303aa2a48792283905f6f9f36aa54f63a8648b2022d6f326e869a7f08830bbe43c53c2	t	2025-03-08 20:43:58.14956
1	admin	admin	$f0ck$3a77cb9806282899e8a9aaa283902c6d:d09006480fe797299ebcd6b7f4912d2518ed316384311072bd0b569c424fd112013f73401a415710fca935ad78608d56fba108bd4138ef976d1e0bb5157d862c	t	2025-03-08 21:17:32.420243
\.


--
-- TOC entry 3479 (class 0 OID 16445)
-- Dependencies: 231
-- Data for Name: user_alias; Type: TABLE DATA; Schema: public; Owner: f0ck
--

COPY public.user_alias (userid, alias) FROM stdin;
\.


--
-- TOC entry 3480 (class 0 OID 16448)
-- Dependencies: 232
-- Data for Name: user_options; Type: TABLE DATA; Schema: public; Owner: f0ck
--

COPY public.user_options (user_id, mode, theme, avatar, fullscreen) FROM stdin;
2	3	iced	\N	0
\.


--
-- TOC entry 3482 (class 0 OID 16454)
-- Dependencies: 234
-- Data for Name: user_sessions; Type: TABLE DATA; Schema: public; Owner: f0ck
--

COPY public.user_sessions (id, user_id, session, browser, created_at, last_used, kmsi) FROM stdin;
4	2	f82f860a4672090c30ab811f3e5d3733	Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0	1741463598	1741463598	0
3	2	5c1320d424ccfb2b6197c0b589dd38cc	Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36	1741463549	1741465645	0
1	2	e2ea9ecfc902d63f2dd7abb7e4fcce7f	Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36	1741463071	1741463425	0
2	2	fdb5d067cb911620e931ee40b987fc3b	Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36	1741463444	1741463524	0
\.


--
-- TOC entry 3492 (class 0 OID 0)
-- Dependencies: 219
-- Name: items_id_seq; Type: SEQUENCE SET; Schema: public; Owner: f0ck
--

SELECT pg_catalog.setval('public.items_id_seq', 1, false);


--
-- TOC entry 3493 (class 0 OID 0)
-- Dependencies: 225
-- Name: tags_id_seq; Type: SEQUENCE SET; Schema: public; Owner: f0ck
--

SELECT pg_catalog.setval('public.tags_id_seq', 3, true);


--
-- TOC entry 3494 (class 0 OID 0)
-- Dependencies: 227
-- Name: user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: f0ck
--

SELECT pg_catalog.setval('public.user_id_seq', 2, true);


--
-- TOC entry 3495 (class 0 OID 0)
-- Dependencies: 233
-- Name: user_sessions_id_seq; Type: SEQUENCE SET; Schema: public; Owner: f0ck
--

SELECT pg_catalog.setval('public.user_sessions_id_seq', 4, true);


--
-- TOC entry 3281 (class 2606 OID 16460)
-- Name: favorites idx_16521_primary; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.favorites
    ADD CONSTRAINT idx_16521_primary PRIMARY KEY (user_id, item_id);


--
-- TOC entry 3283 (class 2606 OID 16462)
-- Name: items idx_16526_primary; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.items
    ADD CONSTRAINT idx_16526_primary PRIMARY KEY (id);


--
-- TOC entry 3297 (class 2606 OID 16464)
-- Name: user idx_16554_primary; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public."user"
    ADD CONSTRAINT idx_16554_primary PRIMARY KEY (id);


--
-- TOC entry 3303 (class 2606 OID 16466)
-- Name: user_options idx_16567_user_id; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.user_options
    ADD CONSTRAINT idx_16567_user_id UNIQUE (user_id);


--
-- TOC entry 3307 (class 2606 OID 16468)
-- Name: user_sessions idx_16572_primary; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.user_sessions
    ADD CONSTRAINT idx_16572_primary PRIMARY KEY (id);


--
-- TOC entry 3285 (class 2606 OID 16470)
-- Name: items items_checksum; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.items
    ADD CONSTRAINT items_checksum UNIQUE (checksum);


--
-- TOC entry 3299 (class 2606 OID 16472)
-- Name: tags_alias tags_alias_tag_alias_tag_orig_id; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.tags_alias
    ADD CONSTRAINT tags_alias_tag_alias_tag_orig_id UNIQUE (tag_alias, tag_orig_id);


--
-- TOC entry 3301 (class 2606 OID 16474)
-- Name: tags_alias tags_alias_tag_orig_id; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.tags_alias
    ADD CONSTRAINT tags_alias_tag_orig_id PRIMARY KEY (tag_orig_id);


--
-- TOC entry 3287 (class 2606 OID 16476)
-- Name: tags_assign tags_assign_item_id_tag_id_primary; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.tags_assign
    ADD CONSTRAINT tags_assign_item_id_tag_id_primary PRIMARY KEY (item_id, tag_id);


--
-- TOC entry 3289 (class 2606 OID 16478)
-- Name: tags_assign tags_assign_item_id_tag_id_unique; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.tags_assign
    ADD CONSTRAINT tags_assign_item_id_tag_id_unique UNIQUE (item_id, tag_id);


--
-- TOC entry 3291 (class 2606 OID 16480)
-- Name: tags tags_id; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.tags
    ADD CONSTRAINT tags_id PRIMARY KEY (id);


--
-- TOC entry 3293 (class 2606 OID 16482)
-- Name: tags tags_normalized; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.tags
    ADD CONSTRAINT tags_normalized UNIQUE (normalized);


--
-- TOC entry 3295 (class 2606 OID 16484)
-- Name: tags tags_tag; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.tags
    ADD CONSTRAINT tags_tag UNIQUE (tag);


--
-- TOC entry 3305 (class 2606 OID 16486)
-- Name: user_options user_options_user_id; Type: CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.user_options
    ADD CONSTRAINT user_options_user_id PRIMARY KEY (user_id);


--
-- TOC entry 3465 (class 2618 OID 16409)
-- Name: items_li _RETURN; Type: RULE; Schema: public; Owner: f0ck
--

CREATE OR REPLACE VIEW public.items_li AS
 SELECT items.id,
    items.src,
    items.dest,
    items.mime,
    items.size,
    items.checksum,
    items.username,
    items.userchannel,
    items.usernetwork,
    items.stamp
   FROM ((public.items
     JOIN public.tags_assign ta1 ON (((ta1.tag_id = 1) AND (ta1.item_id = items.id))))
     JOIN public.tags_assign ta2 ON (((NOT (ta2.tag_id IN ( SELECT tags_nsfp.id
           FROM public.tags_nsfp))) AND (ta2.item_id = items.id))))
  WHERE items.active
  GROUP BY items.id;


--
-- TOC entry 3317 (class 2620 OID 16488)
-- Name: tags_assign tags_assign_ad; Type: TRIGGER; Schema: public; Owner: f0ck
--

CREATE TRIGGER tags_assign_ad AFTER DELETE ON public.tags_assign FOR EACH ROW EXECUTE FUNCTION public.delete_unused_tags();


--
-- TOC entry 3318 (class 2620 OID 16489)
-- Name: tags tags_bi; Type: TRIGGER; Schema: public; Owner: f0ck
--

CREATE TRIGGER tags_bi BEFORE INSERT ON public.tags FOR EACH ROW EXECUTE FUNCTION public.fill_normalized();


--
-- TOC entry 3319 (class 2620 OID 16490)
-- Name: tags tags_bu; Type: TRIGGER; Schema: public; Owner: f0ck
--

CREATE TRIGGER tags_bu BEFORE UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION public.fill_normalized();


--
-- TOC entry 3308 (class 2606 OID 16491)
-- Name: favorites favorites_item_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.favorites
    ADD CONSTRAINT favorites_item_id_fkey FOREIGN KEY (item_id) REFERENCES public.items(id) ON DELETE CASCADE;


--
-- TOC entry 3309 (class 2606 OID 16496)
-- Name: favorites favorites_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.favorites
    ADD CONSTRAINT favorites_user_id_fkey FOREIGN KEY (user_id) REFERENCES public."user"(id) ON DELETE CASCADE;


--
-- TOC entry 3313 (class 2606 OID 16501)
-- Name: tags_alias tags_alias_tag_orig_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.tags_alias
    ADD CONSTRAINT tags_alias_tag_orig_id_fkey FOREIGN KEY (tag_orig_id) REFERENCES public.tags(id) ON DELETE CASCADE;


--
-- TOC entry 3310 (class 2606 OID 16506)
-- Name: tags_assign tags_assign_item_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.tags_assign
    ADD CONSTRAINT tags_assign_item_id_fkey FOREIGN KEY (item_id) REFERENCES public.items(id) ON DELETE CASCADE;


--
-- TOC entry 3311 (class 2606 OID 16511)
-- Name: tags_assign tags_assign_tag_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.tags_assign
    ADD CONSTRAINT tags_assign_tag_id_fkey FOREIGN KEY (tag_id) REFERENCES public.tags(id) ON DELETE CASCADE;


--
-- TOC entry 3312 (class 2606 OID 16516)
-- Name: tags_assign tags_assign_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.tags_assign
    ADD CONSTRAINT tags_assign_user_id_fkey FOREIGN KEY (user_id) REFERENCES public."user"(id) ON DELETE SET DEFAULT;


--
-- TOC entry 3314 (class 2606 OID 16521)
-- Name: user_options user_options_avatar_fkey; Type: FK CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.user_options
    ADD CONSTRAINT user_options_avatar_fkey FOREIGN KEY (avatar) REFERENCES public.items(id) ON DELETE SET DEFAULT;


--
-- TOC entry 3315 (class 2606 OID 16526)
-- Name: user_options user_options_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.user_options
    ADD CONSTRAINT user_options_user_id_fkey FOREIGN KEY (user_id) REFERENCES public."user"(id) ON DELETE CASCADE;


--
-- TOC entry 3316 (class 2606 OID 16531)
-- Name: user_sessions user_sessions_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: f0ck
--

ALTER TABLE ONLY public.user_sessions
    ADD CONSTRAINT user_sessions_user_id_fkey FOREIGN KEY (user_id) REFERENCES public."user"(id) ON DELETE CASCADE;


--
-- TOC entry 3489 (class 0 OID 0)
-- Dependencies: 6
-- Name: SCHEMA public; Type: ACL; Schema: -; Owner: pg_database_owner
--

REVOKE USAGE ON SCHEMA public FROM PUBLIC;
GRANT ALL ON SCHEMA public TO PUBLIC;


-- Completed on 2025-03-08 21:37:57 CET

--
-- PostgreSQL database dump complete
--

