Перенести и адаптировать обязательный минимум лабораторной 6

This commit is contained in:
2026-12-04 06:42:43 +03:00
parent 20afc2c790
commit cb7824c14c
37 changed files with 2292 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
ALTER TABLE messages DROP CONSTRAINT messages_text_check;␍
ALTER TABLE messages ADD CONSTRAINT messages_text_limit CHECK (length(text)<=4000);␍
CREATE TABLE attachments (␍
id uuid PRIMARY KEY, chat_id uuid NOT NULL REFERENCES chats(id),␍
owner_id uuid NOT NULL REFERENCES users(id), object_key text NOT NULL UNIQUE,␍
filename text NOT NULL, content_type text NOT NULL, size_bytes integer NOT NULL,␍
sha256 char(64) NOT NULL, state text NOT NULL CHECK(state IN ('ready','missing')),␍
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),␍
updated_at timestamptz NOT NULL DEFAULT clock_timestamp(),␍
FOREIGN KEY(chat_id,owner_id) REFERENCES chat_members(chat_id,user_id)␍
);␍
CREATE TABLE message_attachments (␍
message_id uuid NOT NULL REFERENCES messages(id), attachment_id uuid NOT NULL REFERENCES attachments(id),␍
position integer NOT NULL, PRIMARY KEY(message_id,attachment_id), UNIQUE(message_id,position)␍
);␍
-- Старые сохранённые ключи теперь сравнивают полное нормализованное тело.␍
UPDATE message_requests SET body=json_build_object('text',body,'attachment_ids',json_build_array())::text;␍