fix(migration-133): dedup via cascade-delete, not child re-point (prod hotfix) #1914

Merged
bot-backend merged 1 commit from fix/migration-133-offer-price-history-collision into main 2026-06-26 08:16:28 +00:00

1 commit

Author SHA1 Message Date
f1141f3578 fix(migration-133): dedup via cascade-delete, not child re-point (prod hotfix)
All checks were successful
CI / changes (pull_request) Successful in 6s
CI / backend-tests (pull_request) Has been skipped
CI / frontend-tests (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Has been skipped
Migration 133 FAILED on prod: offer_price_history has UNIQUE (listing_id,
change_time), but the re-point UPDATE moved ALL loser rows to the keeper →
duplicate key violation (the deep-review validated on a throwaway schema subset
that lacked this constraint). A keeper-only NOT EXISTS guard is also insufficient
— multiple losers in one (source,source_id) group share a change_time, so they
collide WITH EACH OTHER inside the single UPDATE (same vulnerability for
listings_snapshots PK + external_valuations partial-UNIQUE).

Fix: drop all data-child re-points; rely on FK ON DELETE CASCADE (all four FKs
are confdeltype='c') to clean loser children when losers are deleted. Keep only
the collision-free merged_into re-point. These are duplicates of the SAME offer —
the keeper retains its own full history; loser-dup history is redundant.

Dry-run on prod (BEGIN…ROLLBACK): 9840 groups, 9889 losers deleted, index
created, abort-guard passed, zero errors. Migration 133 never applied anywhere
(absent from _schema_migrations), so amending it in place is safe.

Refs #1773
2026-06-26 13:14:57 +05:00