-- WARNING: This schema is for context only and is not meant to be run. -- Table order and constraints may not be valid for execution. CREATE TABLE public.categories ( id uuid NOT NULL DEFAULT gen_random_uuid(), name text NOT NULL, slug text NOT NULL, created_at timestamp with time zone DEFAULT timezone('utc'::text, now()), color text, user_id uuid, CONSTRAINT categories_pkey PRIMARY KEY (id), CONSTRAINT categories_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ); CREATE TABLE public.collections ( id uuid NOT NULL DEFAULT gen_random_uuid(), user_id uuid NOT NULL, name text NOT NULL, created_at timestamp with time zone DEFAULT timezone('utc'::text, now()), CONSTRAINT collections_pkey PRIMARY KEY (id), CONSTRAINT collections_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ); CREATE TABLE public.profiles ( id uuid NOT NULL, username text, created_at timestamp with time zone DEFAULT timezone('utc'::text, now()), avatar_url text, CONSTRAINT profiles_pkey PRIMARY KEY (id), CONSTRAINT profiles_id_fkey FOREIGN KEY (id) REFERENCES auth.users(id) ); CREATE TABLE public.snippet_categories ( snippet_id uuid NOT NULL, category_id uuid NOT NULL, created_at timestamp with time zone DEFAULT timezone('utc'::text, now()), CONSTRAINT snippet_categories_pkey PRIMARY KEY (snippet_id, category_id), CONSTRAINT snippet_categories_snippet_id_fkey FOREIGN KEY (snippet_id) REFERENCES public.snippets(id), CONSTRAINT snippet_categories_category_id_fkey FOREIGN KEY (category_id) REFERENCES public.categories(id) ); CREATE TABLE public.snippet_collections ( snippet_id uuid NOT NULL, collection_id uuid NOT NULL, created_at timestamp with time zone DEFAULT timezone('utc'::text, now()), CONSTRAINT snippet_collections_pkey PRIMARY KEY (snippet_id, collection_id), CONSTRAINT snippet_collections_snippet_id_fkey FOREIGN KEY (snippet_id) REFERENCES public.snippets(id), CONSTRAINT snippet_collections_collection_id_fkey FOREIGN KEY (collection_id) REFERENCES public.collections(id) ); CREATE TABLE public.snippet_groups ( id uuid NOT NULL DEFAULT gen_random_uuid(), user_id uuid NOT NULL, name text NOT NULL, description text, created_at timestamp with time zone DEFAULT timezone('utc'::text, now()), CONSTRAINT snippet_groups_pkey PRIMARY KEY (id), CONSTRAINT snippet_groups_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ); CREATE TABLE public.snippet_groups_relation ( snippet_id uuid NOT NULL, group_id uuid NOT NULL, created_at timestamp with time zone DEFAULT timezone('utc'::text, now()), CONSTRAINT snippet_groups_relation_pkey PRIMARY KEY (snippet_id, group_id), CONSTRAINT snippet_groups_relation_snippet_id_fkey FOREIGN KEY (snippet_id) REFERENCES public.snippets(id), CONSTRAINT snippet_groups_relation_group_id_fkey FOREIGN KEY (group_id) REFERENCES public.snippet_groups(id) ); CREATE TABLE public.snippet_tags ( snippet_id uuid NOT NULL, tag_id uuid NOT NULL, CONSTRAINT snippet_tags_pkey PRIMARY KEY (snippet_id, tag_id), CONSTRAINT snippet_tags_snippet_id_fkey FOREIGN KEY (snippet_id) REFERENCES public.snippets(id), CONSTRAINT snippet_tags_tag_id_fkey FOREIGN KEY (tag_id) REFERENCES public.tags(id) ); CREATE TABLE public.snippets ( id uuid NOT NULL DEFAULT gen_random_uuid(), user_id uuid NOT NULL, title text NOT NULL, description text, code text NOT NULL, language USER-DEFINED NOT NULL DEFAULT 'JavaScript'::language, tags ARRAY DEFAULT '{}'::text[], created_at timestamp with time zone DEFAULT timezone('utc'::text, now()), updated_at timestamp with time zone DEFAULT timezone('utc'::text, now()), is_favorite boolean DEFAULT false, is_public boolean DEFAULT false, share_token uuid, demo_url text, CONSTRAINT snippets_pkey PRIMARY KEY (id), CONSTRAINT snippets_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ); CREATE TABLE public.tags ( id uuid NOT NULL DEFAULT gen_random_uuid(), user_id uuid NOT NULL, name text NOT NULL, created_at timestamp with time zone DEFAULT timezone('utc'::text, now()), CONSTRAINT tags_pkey PRIMARY KEY (id), CONSTRAINT tags_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) );