13 lines
488 B
SQL
13 lines
488 B
SQL
CREATE TABLE message_attachments (
|
|
message_id uuid NOT NULL REFERENCES messages(id) ON DELETE CASCADE,
|
|
attachment_id uuid NOT NULL REFERENCES attachments(id),
|
|
position integer NOT NULL CHECK (position >= 0 AND position < 10),
|
|
PRIMARY KEY (message_id, attachment_id)
|
|
);
|
|
|
|
CREATE INDEX message_attachments_attachment_idx
|
|
ON message_attachments (attachment_id);
|
|
|
|
CREATE UNIQUE INDEX message_attachments_order_idx
|
|
ON message_attachments (message_id, position);
|