feat(lab4): implement S3 attachments with fault tolerance

This commit is contained in:
sashadugina06
2026-11-06 18:15:53 +03:00
parent ec540a1a72
commit b4704b47b2
67 changed files with 3436 additions and 46 deletions
+16
View File
@@ -0,0 +1,16 @@
CREATE TABLE attachments (
id UUID PRIMARY KEY,
chat_id UUID NOT NULL REFERENCES chats(id),
owner_id UUID NOT NULL REFERENCES users(id),
filename TEXT NOT NULL,
object_key TEXT NOT NULL UNIQUE,
size_bytes BIGINT NOT NULL CHECK (size_bytes BETWEEN 1 AND 10485760),
content_type TEXT NOT NULL CHECK (content_type IN ('image/png', 'image/jpeg')),
sha256 CHAR(64) NOT NULL,
status TEXT NOT NULL DEFAULT 'ready' CHECK (status = 'ready'),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
ALTER TABLE messages DROP CONSTRAINT messages_text_check;
ALTER TABLE messages ADD COLUMN attachment_ids UUID[] NOT NULL DEFAULT '{}';
ALTER TABLE messages ADD CHECK (length(text) <= 4000 AND (length(btrim(text)) > 0 OR cardinality(attachment_ids) > 0));