This commit is contained in:
2026-10-23 17:49:14 +03:00
parent 1fddc0e76c
commit f39147689a
23 changed files with 1351 additions and 10 deletions
+23 -1
View File
@@ -68,6 +68,22 @@ CREATE TABLE idempotency_keys (
CONSTRAINT ck_idem_status_body_paired CHECK ((status_code IS NULL) = (response_body IS NULL))
);
CREATE TABLE attachments (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
object_key VARCHAR(512) NOT NULL,
filename VARCHAR(255) NOT NULL,
content_type VARCHAR(100) NOT NULL,
size_bytes BIGINT NOT NULL,
checksum VARCHAR(64) NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'READY'
CHECK (status IN ('UPLOADING', 'READY', 'BROKEN')),
chat_id UUID NOT NULL REFERENCES chats(id) ON DELETE CASCADE,
owner_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT uq_attachments_object_key UNIQUE (object_key)
);
-- Keyset pagination: ORDER BY created_at ASC, id ASC (JPQL uses ASC)
CREATE INDEX idx_messages_chat_created_asc_id
ON messages (chat_id, created_at ASC, id ASC);
@@ -91,4 +107,10 @@ CREATE INDEX idx_sessions_expires_active
WHERE revoked_at IS NULL;
CREATE INDEX idx_idempotency_created
ON idempotency_keys (created_at);
ON idempotency_keys (created_at);
CREATE INDEX idx_attachments_object_key ON attachments(object_key);
CREATE INDEX idx_attachments_chat_id ON attachments(chat_id);
CREATE INDEX idx_attachments_owner_id ON attachments(owner_id);
CREATE INDEX idx_attachments_status ON attachments(status);
CREATE INDEX idx_attachments_created_at ON attachments(created_at);