refactor: isolate attachment lifecycle

This commit is contained in:
2026-10-09 13:13:59 +03:00
parent ad36ab8a92
commit cc4ac1ddd7
33 changed files with 1672 additions and 982 deletions
+16
View File
@@ -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);