forked from mtusi2026/mtusi2026lab4
feat(lab4): implement S3 attachments and image validation
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
-- Object bytes are deliberately NOT stored in the database.
|
||||
CREATE TABLE attachments (
|
||||
id UUID PRIMARY KEY,
|
||||
chat_id UUID NOT NULL REFERENCES chats(id),
|
||||
owner_id UUID NOT NULL REFERENCES users(id),
|
||||
filename VARCHAR(255) NOT NULL,
|
||||
content_type VARCHAR(10) NOT NULL CHECK (content_type IN ('image/png','image/jpeg')),
|
||||
size_bytes INTEGER NOT NULL CHECK (size_bytes BETWEEN 1 AND 10485760),
|
||||
sha256 CHAR(64) NOT NULL,
|
||||
status VARCHAR(12) NOT NULL DEFAULT 'ready' CHECK (status = 'ready'),
|
||||
object_key TEXT NOT NULL UNIQUE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE INDEX attachments_chat_idx ON attachments (chat_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 CHECK (position BETWEEN 0 AND 9),
|
||||
PRIMARY KEY (message_id, attachment_id),
|
||||
UNIQUE (message_id, position)
|
||||
);
|
||||
Reference in New Issue
Block a user