fix(upload): stop a late retry from undoing a host takedown
Migration 026 freed the idempotency key as soon as deleted_at was set, so a
retry after a delete uploads afresh instead of 409ing forever. That rationale
only considered the GUEST deleting. deleted_at is also set by
host_delete_upload, and there the same rule reverses a moderation decision:
1. Guest uploads; the row commits and the photo appears, but the response
is lost on the way back — the flaky-wifi case the key exists for — so
the phone keeps the queue item.
2. The host takes the photo down. Epoch bumped, keepsake rebuilt without it.
3. The phone reconnects ten minutes later and retries. The key is free, the
INSERT succeeds, and the photo is back — in the feed and in the next
keepsake, under a NEW uuid that matches nothing in the host's moderation
history, with nothing logged to say a takedown was reversed.
Migration 031 keeps the key claimed for a host takedown and releases it only
for a guest's own delete, so the retry resolves to the duplicate path and is
refused. The refusal now says why ("von den Gastgebern entfernt") rather than
"already processed", which invites another try.
The index predicate and the ON CONFLICT arbiter are changed in lockstep;
these queries are not compile-checked, so a drift between them is a 500 on
exactly the retries the index exists to serve. Verified against a real
Postgres: live retry suppressed, host takedown holds the key, guest delete
releases it. The integration test's copy of the insert is updated too — it is
verbatim by design, and a stale copy would have kept passing.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
-- Restore migration 026's predicate, then drop the column it depended on.
|
||||
--
|
||||
-- Note the same pairing caveat 026's own down carries: this is only valid alongside a code
|
||||
-- rollback. `Upload::create` sends an ON CONFLICT predicate that must match the live index, so
|
||||
-- running this down against the current binary makes every keyed upload a runtime 500.
|
||||
DROP INDEX IF EXISTS upload_client_upload_id_key;
|
||||
CREATE UNIQUE INDEX upload_client_upload_id_key ON upload (client_upload_id)
|
||||
WHERE client_upload_id IS NOT NULL AND deleted_at IS NULL;
|
||||
|
||||
ALTER TABLE upload DROP COLUMN IF EXISTS taken_down_by_host;
|
||||
Reference in New Issue
Block a user