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

This commit is contained in:
2026-11-27 16:36:53 +03:00
parent 470d9d6f1e
commit 5c3c4a9d0d
49 changed files with 2366 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;␍