This commit is contained in:
pampixz
2026-11-12 14:37:43 +03:00
parent ec540a1a72
commit 6a7f4ec7d4
17 changed files with 749 additions and 24 deletions
+12
View File
@@ -0,0 +1,12 @@
ALTER TABLE messages DROP CONSTRAINT IF EXISTS messages_text_check;
ALTER TABLE messages ADD COLUMN IF NOT EXISTS attachment_ids uuid[] NOT NULL DEFAULT '{}';
ALTER TABLE messages ADD CONSTRAINT messages_content_check CHECK (length(trim(text))>0 OR cardinality(attachment_ids)>0);
CREATE TABLE IF NOT EXISTS attachments (
id uuid PRIMARY KEY, chat_id uuid NOT NULL REFERENCES chats(id) ON DELETE CASCADE,
owner_id uuid NOT NULL REFERENCES users(id), filename varchar(255) NOT NULL,
content_type varchar(20) NOT NULL, size_bytes integer NOT NULL,
sha256 char(64) NOT NULL, status varchar(20) NOT NULL DEFAULT 'ready',
object_key text NOT NULL UNIQUE, created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_attachments_chat ON attachments(chat_id);