-
Notifications
You must be signed in to change notification settings - Fork 3
/
0000_bored_mulholland_black.sql
40 lines (40 loc) · 1.39 KB
/
0000_bored_mulholland_black.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
CREATE TABLE IF NOT EXISTS "documents" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"title" text NOT NULL,
"data" text,
"icon" text NOT NULL,
"banner" text,
"in_trash" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"parent_id" uuid,
"workspace_id" uuid NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "workspaces" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"title" text NOT NULL,
"data" text,
"icon" text NOT NULL,
"logo" text,
"banner" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"workspace_owner" uuid NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "documents" ADD CONSTRAINT "documents_parent_id_documents_id_fk" FOREIGN KEY ("parent_id") REFERENCES "documents"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "documents" ADD CONSTRAINT "documents_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "workspaces"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "workspaces" ADD CONSTRAINT "workspaces_workspace_owner_users_id_fk" FOREIGN KEY ("workspace_owner") REFERENCES "users"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;