Files
mtusi2026lab4/prisma/migrations/20261108000000_attachments/migration.sql
T
qrtx dc46ac213d feat(storage): add RustFS attachments and presigned uploads
Add two API replicas, safe object reconciliation, upload validation, regression tests and documented load experiments.
2026-11-12 10:16:39 +03:00

21 lines
1.1 KiB
SQL

ALTER TABLE "messages" ADD COLUMN "attachment_ids" UUID[] NOT NULL DEFAULT ARRAY[]::UUID[];
CREATE TABLE "attachments" (
"id" UUID NOT NULL,
"chat_id" UUID NOT NULL,
"owner_id" UUID NOT NULL,
"object_key" TEXT NOT NULL,
"filename" VARCHAR(255) NOT NULL,
"content_type" VARCHAR(32) NOT NULL,
"size_bytes" INTEGER NOT NULL CHECK ("size_bytes" BETWEEN 1 AND 10485760),
"sha256" CHAR(64) NOT NULL,
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "attachments_pkey" PRIMARY KEY ("id"),
CONSTRAINT "attachments_chat_id_fkey" FOREIGN KEY ("chat_id") REFERENCES "chats"("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "attachments_owner_id_fkey" FOREIGN KEY ("owner_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
CREATE UNIQUE INDEX "attachments_object_key_key" ON "attachments"("object_key");
CREATE INDEX "attachments_chat_id_idx" ON "attachments"("chat_id");
CREATE INDEX "attachments_owner_id_idx" ON "attachments"("owner_id");