Skip to main content

max / makenotwork

706 B · 12 lines History Blame Raw
1 -- Make pending_uploads uniqueness (and its ON CONFLICT target) bucket-aware.
2 --
3 -- The deletion queue (pending_s3_deletions) and is_s3_key_live are already
4 -- (s3_key, bucket)-scoped; pending_uploads lagged on s3_key alone. Today every
5 -- pending row is bucket='main', so this is latent, but a key legitimately
6 -- present in two buckets (main + a future synckit/OTA presign) would collide on
7 -- INSERT and the ON CONFLICT (s3_key) upsert could refresh or suppress the
8 -- wrong bucket's row. Align the unique key with the rest of the storage layer.
9 DROP INDEX IF EXISTS idx_pending_uploads_s3_key;
10 CREATE UNIQUE INDEX IF NOT EXISTS idx_pending_uploads_s3_key_bucket
11 ON pending_uploads(s3_key, bucket);
12