21 lines
1.2 KiB
SQL
21 lines
1.2 KiB
SQL
CREATE TABLE "notifications" (
|
|||
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||
|
|
"user_id" uuid NOT NULL,
|
||
|
|
"workspace_id" uuid,
|
||
|
|
"type" text NOT NULL,
|
||
|
|
"title" text NOT NULL,
|
||
|
|
"body" text,
|
||
|
|
"entity_type" text,
|
||
|
|
"entity_id" uuid,
|
||
|
|
"read_at" timestamp with time zone,
|
||
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||
|
|
"deleted_at" timestamp with time zone
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_workspace_id_domains_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."domains"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
CREATE INDEX "notifications_user_id_idx" ON "notifications" USING btree ("user_id");--> statement-breakpoint
|
||
|
|
CREATE INDEX "notifications_user_read_idx" ON "notifications" USING btree ("user_id","read_at");--> statement-breakpoint
|
||
|
|
CREATE INDEX "notifications_workspace_id_idx" ON "notifications" USING btree ("workspace_id");--> statement-breakpoint
|
||
|
|
CREATE INDEX "notifications_entity_idx" ON "notifications" USING btree ("entity_type","entity_id");
|