Files
mtusi2026lab3-fork/prisma/migrations/20261013150000_message_epoch_buckets/migration.sql
T
qrtx 24f32c3fbe feat(api): implement persistent messaging and graceful draining
Add shared sessions, cached message history and transactional idempotency backed by PostgreSQL. Return readiness 503 during draining and finish in-flight requests before closing dependencies.
2026-10-29 11:46:28 +03:00

14 lines
601 B
SQL

CREATE TABLE "chat_message_epochs" (
"chat_id" UUID NOT NULL,
"bucket" SMALLINT NOT NULL,
"epoch" BIGINT NOT NULL DEFAULT 0,
CONSTRAINT "chat_message_epochs_pkey" PRIMARY KEY ("chat_id", "bucket"),
CONSTRAINT "chat_message_epochs_bucket_check" CHECK ("bucket" BETWEEN 0 AND 15),
CONSTRAINT "chat_message_epochs_chat_id_fkey" FOREIGN KEY ("chat_id") REFERENCES "chats"("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "chat_message_epochs" ("chat_id", "bucket", "epoch")
SELECT "id", 0, "messages_epoch" FROM "chats";
ALTER TABLE "chats" DROP COLUMN "messages_epoch";