forked from mtusi2026/mtusi2026lab5
12 lines
714 B
SQL
12 lines
714 B
SQL
ALTER TABLE messages DROP CONSTRAINT messages_text_check;
|
|
ALTER TABLE messages ADD CONSTRAINT messages_text_check CHECK (char_length(text) <= 4000);
|
|
ALTER TABLE messages ADD COLUMN attachment_ids uuid[] NOT NULL DEFAULT '{}';
|
|
CREATE TABLE attachments (
|
|
id uuid PRIMARY KEY, chat_id uuid NOT NULL REFERENCES chats(id),
|
|
uploader_id uuid NOT NULL REFERENCES users(id), object_key text UNIQUE NOT NULL,
|
|
filename text NOT NULL, content_type text NOT NULL, size_bytes bigint NOT NULL,
|
|
sha256 text NOT NULL, status text NOT NULL CHECK(status IN ('pending','ready')),
|
|
created_at timestamptz NOT NULL DEFAULT clock_timestamp()
|
|
);
|
|
CREATE INDEX attachments_pending_idx ON attachments(created_at) WHERE status='pending';
|