forked from mtusi2026/mtusi2026lab4
refactor: isolate attachment lifecycle
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
ALTER TABLE attachments
|
||||
ADD COLUMN status TEXT NOT NULL DEFAULT 'ready',
|
||||
ADD COLUMN ready_at TIMESTAMPTZ DEFAULT clock_timestamp();
|
||||
|
||||
UPDATE attachments
|
||||
SET ready_at = created_at;
|
||||
|
||||
ALTER TABLE attachments
|
||||
ADD CONSTRAINT attachments_status CHECK (status IN ('pending', 'ready', 'deleting')),
|
||||
ADD CONSTRAINT attachments_ready_at CHECK (
|
||||
(status = 'pending' AND ready_at IS NULL) OR
|
||||
(status IN ('ready', 'deleting') AND ready_at IS NOT NULL)
|
||||
);
|
||||
|
||||
CREATE INDEX attachments_status_created_at_object_key_idx
|
||||
ON attachments (status, created_at, object_key);
|
||||
Reference in New Issue
Block a user