36 lines
2.1 KiB
SQL
36 lines
2.1 KiB
SQL
CREATE TABLE "attachment" (
|
|
"id" uuid PRIMARY KEY DEFAULT uuidv7(),
|
|
"uploader_id" text,
|
|
"message_id" uuid,
|
|
"filename" text NOT NULL,
|
|
"content_type" text NOT NULL,
|
|
"size" integer NOT NULL,
|
|
"width" integer,
|
|
"height" integer,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "conversation_read" (
|
|
"user_id" text,
|
|
"conversation_id" uuid,
|
|
"last_read_message_id" uuid NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
CONSTRAINT "conversation_read_pkey" PRIMARY KEY("user_id","conversation_id")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "message_reaction" (
|
|
"message_id" uuid,
|
|
"user_id" text,
|
|
"emoji" text,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
CONSTRAINT "message_reaction_pkey" PRIMARY KEY("message_id","user_id","emoji")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX "attachment_message_id_idx" ON "attachment" ("message_id");--> statement-breakpoint
|
|
CREATE INDEX "attachment_uploader_id_idx" ON "attachment" ("uploader_id");--> statement-breakpoint
|
|
ALTER TABLE "attachment" ADD CONSTRAINT "attachment_uploader_id_user_id_fkey" FOREIGN KEY ("uploader_id") REFERENCES "user"("id") ON DELETE SET NULL;--> statement-breakpoint
|
|
ALTER TABLE "attachment" ADD CONSTRAINT "attachment_message_id_message_id_fkey" FOREIGN KEY ("message_id") REFERENCES "message"("id") ON DELETE SET NULL;--> statement-breakpoint
|
|
ALTER TABLE "conversation_read" ADD CONSTRAINT "conversation_read_user_id_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE CASCADE;--> statement-breakpoint
|
|
ALTER TABLE "conversation_read" ADD CONSTRAINT "conversation_read_conversation_id_conversation_id_fkey" FOREIGN KEY ("conversation_id") REFERENCES "conversation"("id") ON DELETE CASCADE;--> statement-breakpoint
|
|
ALTER TABLE "message_reaction" ADD CONSTRAINT "message_reaction_message_id_message_id_fkey" FOREIGN KEY ("message_id") REFERENCES "message"("id") ON DELETE CASCADE;--> statement-breakpoint
|
|
ALTER TABLE "message_reaction" ADD CONSTRAINT "message_reaction_user_id_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE CASCADE; |