DO $$ BEGIN CREATE TYPE "public"."subscription" AS ENUM('free', 'paid'); EXCEPTION WHEN duplicate_object THEN null; END $$; --> statement-breakpoint CREATE TABLE IF NOT EXISTS "categories" ( "id" serial PRIMARY KEY NOT NULL, "name" text DEFAULT '' NOT NULL, "name_visible" boolean DEFAULT true NOT NULL, "icon" text DEFAULT 'i-ph:circle-wavy-question-duotone' NOT NULL, "color" text DEFAULT 'gray' NOT NULL, "page_id" integer NOT NULL, "created_at" timestamp (3) DEFAULT now(), "updated_at" timestamp (3) ); --> statement-breakpoint CREATE TABLE IF NOT EXISTS "pages" ( "id" serial PRIMARY KEY NOT NULL, "user_id" integer NOT NULL, "created_at" timestamp (3) DEFAULT now(), "updated_at" timestamp (3) ); --> statement-breakpoint CREATE TABLE IF NOT EXISTS "tabs" ( "id" serial PRIMARY KEY NOT NULL, "name" text DEFAULT '' NOT NULL, "name_visible" boolean DEFAULT true NOT NULL, "icon" text DEFAULT 'i-ph:circle-wavy-question-duotone' NOT NULL, "color" text DEFAULT 'gray' NOT NULL, "category_id" integer NOT NULL, "created_at" timestamp (3) DEFAULT now(), "updated_at" timestamp (3) ); --> statement-breakpoint CREATE TABLE IF NOT EXISTS "users" ( "id" serial PRIMARY KEY NOT NULL, "username" text NOT NULL, "name" text NOT NULL, "email" text NOT NULL, "github_id" text, "github_token" text, "google_id" text, "google_token" text, "description" text DEFAULT '', "private" boolean DEFAULT false NOT NULL, "timezone" text DEFAULT 'undefined' NOT NULL, "location" text DEFAULT 'undefined' NOT NULL, "subscription" "subscription" DEFAULT 'free' NOT NULL, "created_at" timestamp (3) DEFAULT now(), "updated_at" timestamp (3), CONSTRAINT "users_email_unique" UNIQUE("email"), CONSTRAINT "users_github_id_unique" UNIQUE("github_id"), CONSTRAINT "users_google_id_unique" UNIQUE("google_id") ); --> statement-breakpoint DO $$ BEGIN ALTER TABLE "categories" ADD CONSTRAINT "categories_page_id_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."pages"("id") ON DELETE cascade ON UPDATE no action; EXCEPTION WHEN duplicate_object THEN null; END $$; --> statement-breakpoint DO $$ BEGIN ALTER TABLE "pages" ADD CONSTRAINT "pages_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; EXCEPTION WHEN duplicate_object THEN null; END $$; --> statement-breakpoint DO $$ BEGIN ALTER TABLE "tabs" ADD CONSTRAINT "tabs_category_id_categories_id_fk" FOREIGN KEY ("category_id") REFERENCES "public"."categories"("id") ON DELETE cascade ON UPDATE no action; EXCEPTION WHEN duplicate_object THEN null; END $$;