ЛР 5: outbox, retry и versioned pipeline — Майорова БВТ2301
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
ALTER TABLE messages
|
||||
DROP CONSTRAINT messages_text_bytes
|
||||
, ADD CONSTRAINT messages_text_bytes CHECK (octet_length(text) BETWEEN 0 AND 16000)
|
||||
, ADD COLUMN attachment_ids UUID[] NOT NULL DEFAULT '{}'
|
||||
;
|
||||
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
|
||||
, content_type TEXT NOT NULL CHECK (content_type IN ('image/png', 'image/jpeg'))
|
||||
, size_bytes BIGINT NOT NULL CHECK (size_bytes BETWEEN 1 AND 10485760)
|
||||
, sha256 CHAR(64) NOT NULL
|
||||
, state TEXT NOT NULL CHECK (state IN ('uploading', 'ready', 'storage_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 INDEX attachments_chat ON attachments (chat_id, id)
|
||||
;
|
||||
CREATE TABLE message_attachments (
|
||||
message_id UUID NOT NULL REFERENCES messages(id)
|
||||
, attachment_id UUID NOT NULL REFERENCES attachments(id)
|
||||
, PRIMARY KEY (message_id, attachment_id)
|
||||
)
|
||||
;
|
||||
CREATE INDEX message_attachments_attachment ON message_attachments (attachment_id)
|
||||
;
|
||||
Reference in New Issue
Block a user