fix(tradein): plain natural-key dedup_hash for rosreestr deals (#576) #638

Merged
Light1YT merged 1 commit from fix/576-dedup-hash-plain-key into main 2026-05-29 06:56:35 +00:00

1 commit

Author SHA1 Message Date
b51893f7c3 fix(tradein): plain natural-key dedup_hash for rosreestr deals (#576)
rosreestr ДКП deals used dedup_hash = md5('ros:dkp:' || id) — a hash of
an already-unique natural key. The md5 is collision-prone (theoretically),
not human-readable, and irreversible (can't recover the source id from it,
which mattered because deals.source_id was never populated).

Replace with the plain natural key 'ros:dkp:' || id (injective, zero
collision, reversible) and populate deals.source_id going forward, in both
the live scheduler import (import_rosreestr_dkp) and the legacy
deploy/import-rosreestr.sh.

Migration 077 backfills the existing 49,791 rows: recovers the original id
from FDW foreign table gendesign_rosreestr_deals by matching the old md5,
then writes the plain key + source_id. Idempotent; plain keys and md5 hex
are format-disjoint so no transient UNIQUE violation on deals_dedup_hash_key.
Verified via prod dry-run (ROLLBACK): UPDATE 49791, 0 md5 remaining, 3.85s.

Closes #576
2026-05-29 11:55:15 +05:00