0000_empty_emma_frost.sql136 lines · main
1CREATE TABLE "accounts" (
2 "id" varchar(30) PRIMARY KEY NOT NULL,
3 "user_id" varchar(30) NOT NULL,
4 "account_id" text NOT NULL,
5 "provider_id" text NOT NULL,
6 "access_token" text,
7 "refresh_token" text,
8 "id_token" text,
9 "access_token_expires_at" timestamp with time zone,
10 "refresh_token_expires_at" timestamp with time zone,
11 "scope" text,
12 "password" text,
13 "created_at" timestamp with time zone DEFAULT now() NOT NULL,
14 "updated_at" timestamp with time zone DEFAULT now() NOT NULL
15);
16--> statement-breakpoint
17CREATE TABLE "api_keys" (
18 "id" varchar(30) PRIMARY KEY NOT NULL,
19 "project_id" varchar(30) NOT NULL,
20 "created_by" varchar(30) NOT NULL,
21 "name" text NOT NULL,
22 "hash" text NOT NULL,
23 "suffix" varchar(4) NOT NULL,
24 "last_used_at" timestamp with time zone,
25 "expires_at" timestamp with time zone,
26 "created_at" timestamp with time zone DEFAULT now() NOT NULL,
27 "revoked_at" timestamp with time zone
28);
29--> statement-breakpoint
30CREATE TABLE "audit_logs" (
31 "id" varchar(30) PRIMARY KEY NOT NULL,
32 "actor_id" varchar(30),
33 "project_id" varchar(30),
34 "action" text NOT NULL,
35 "ip_hash" varchar(64),
36 "user_agent" text,
37 "metadata" jsonb,
38 "created_at" timestamp with time zone DEFAULT now() NOT NULL
39);
40--> statement-breakpoint
41CREATE TABLE "deployments" (
42 "id" varchar(30) PRIMARY KEY NOT NULL,
43 "project_id" varchar(30) NOT NULL,
44 "triggered_by" varchar(30),
45 "api_key_id" varchar(30),
46 "status" text DEFAULT 'pending' NOT NULL,
47 "schema_diff_summary" jsonb,
48 "schema_snapshot" jsonb,
49 "function_count" varchar(12),
50 "function_names" jsonb,
51 "error_code" text,
52 "error_message" text,
53 "started_at" timestamp with time zone,
54 "finished_at" timestamp with time zone,
55 "created_at" timestamp with time zone DEFAULT now() NOT NULL
56);
57--> statement-breakpoint
58CREATE TABLE "project_members" (
59 "project_id" varchar(30) NOT NULL,
60 "user_id" varchar(30) NOT NULL,
61 "role" text DEFAULT 'developer' NOT NULL,
62 "created_at" timestamp with time zone DEFAULT now() NOT NULL,
63 "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
64 CONSTRAINT "project_members_project_id_user_id_pk" PRIMARY KEY("project_id","user_id")
65);
66--> statement-breakpoint
67CREATE TABLE "projects" (
68 "id" varchar(30) PRIMARY KEY NOT NULL,
69 "slug" text NOT NULL,
70 "name" text NOT NULL,
71 "owner_id" varchar(30) NOT NULL,
72 "region" text DEFAULT 'eu-west-1' NOT NULL,
73 "tier" text DEFAULT 'free' NOT NULL,
74 "shard_id" text,
75 "created_at" timestamp with time zone DEFAULT now() NOT NULL,
76 "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
77 "deleted_at" timestamp with time zone
78);
79--> statement-breakpoint
80CREATE TABLE "sessions" (
81 "id" varchar(30) PRIMARY KEY NOT NULL,
82 "user_id" varchar(30) NOT NULL,
83 "token" text NOT NULL,
84 "expires_at" timestamp with time zone NOT NULL,
85 "ip_address" text,
86 "user_agent" text,
87 "created_at" timestamp with time zone DEFAULT now() NOT NULL,
88 "updated_at" timestamp with time zone DEFAULT now() NOT NULL
89);
90--> statement-breakpoint
91CREATE TABLE "users" (
92 "id" varchar(30) PRIMARY KEY NOT NULL,
93 "email" text NOT NULL,
94 "email_verified" boolean DEFAULT false NOT NULL,
95 "name" text,
96 "image" text,
97 "created_at" timestamp with time zone DEFAULT now() NOT NULL,
98 "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
99 "deleted_at" timestamp with time zone
100);
101--> statement-breakpoint
102CREATE TABLE "verifications" (
103 "id" varchar(30) PRIMARY KEY NOT NULL,
104 "identifier" text NOT NULL,
105 "value" text NOT NULL,
106 "expires_at" timestamp with time zone NOT NULL,
107 "created_at" timestamp with time zone DEFAULT now() NOT NULL,
108 "updated_at" timestamp with time zone DEFAULT now() NOT NULL
109);
110--> statement-breakpoint
111ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
112ALTER TABLE "api_keys" ADD CONSTRAINT "api_keys_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
113ALTER TABLE "api_keys" ADD CONSTRAINT "api_keys_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
114ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_actor_id_users_id_fk" FOREIGN KEY ("actor_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
115ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
116ALTER TABLE "deployments" ADD CONSTRAINT "deployments_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
117ALTER TABLE "deployments" ADD CONSTRAINT "deployments_triggered_by_users_id_fk" FOREIGN KEY ("triggered_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
118ALTER TABLE "deployments" ADD CONSTRAINT "deployments_api_key_id_api_keys_id_fk" FOREIGN KEY ("api_key_id") REFERENCES "public"."api_keys"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
119ALTER TABLE "project_members" ADD CONSTRAINT "project_members_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
120ALTER TABLE "project_members" ADD CONSTRAINT "project_members_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
121ALTER TABLE "projects" ADD CONSTRAINT "projects_owner_id_users_id_fk" FOREIGN KEY ("owner_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
122ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
123CREATE INDEX "accounts_user_id_idx" ON "accounts" USING btree ("user_id");--> statement-breakpoint
124CREATE UNIQUE INDEX "accounts_provider_account_idx" ON "accounts" USING btree ("provider_id","account_id");--> statement-breakpoint
125CREATE UNIQUE INDEX "api_keys_hash_idx" ON "api_keys" USING btree ("hash");--> statement-breakpoint
126CREATE INDEX "api_keys_project_idx" ON "api_keys" USING btree ("project_id");--> statement-breakpoint
127CREATE INDEX "audit_logs_project_created_idx" ON "audit_logs" USING btree ("project_id","created_at");--> statement-breakpoint
128CREATE INDEX "audit_logs_actor_created_idx" ON "audit_logs" USING btree ("actor_id","created_at");--> statement-breakpoint
129CREATE INDEX "deployments_project_created_idx" ON "deployments" USING btree ("project_id","created_at");--> statement-breakpoint
130CREATE INDEX "deployments_status_idx" ON "deployments" USING btree ("status");--> statement-breakpoint
131CREATE UNIQUE INDEX "projects_slug_idx" ON "projects" USING btree ("slug");--> statement-breakpoint
132CREATE INDEX "projects_owner_idx" ON "projects" USING btree ("owner_id");--> statement-breakpoint
133CREATE UNIQUE INDEX "sessions_token_idx" ON "sessions" USING btree ("token");--> statement-breakpoint
134CREATE INDEX "sessions_user_id_idx" ON "sessions" USING btree ("user_id");--> statement-breakpoint
135CREATE UNIQUE INDEX "users_email_idx" ON "users" USING btree ("email");--> statement-breakpoint
136CREATE INDEX "verifications_identifier_idx" ON "verifications" USING btree ("identifier");