fix(tradein-sql): remove duplicate CREATE INDEX from 050 (regression from PR #500) #515
No reviewers
Labels
No labels
admin
analytics
auth
automation
bug
business
chore
ci
compliance
data
data-moat
docs
duplicate
dx
enhancement
Fable 5 ревью
feedback/max
generative
GG-форсайт
needs-discussion
needs-human
observability
pause-bots
performance
priority/p0
priority/p1
priority/p2
priority/p3
scope/backend
scope/db
scope/devops
scope/frontend
scope/qa
scrapers
security
site-finder
stage/1
stage/2
status/blocked
status/done
status/needs-analysis
status/needs-fix
status/qa
status/ready
status/review
status/wip
tech-debt
tradein
ux
week ревью 1
wontfix
вторичка
ИРД
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#515
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/tradein-050-remove-dup-index-creates"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary — production regression confirmed
PR #500 added
035_drop_duplicate_indexes.sqlto droplisting_sources_listing_idx2andhouses_geom_idx2. Migration ran. But on 2026-05-24 ~12:08 production audit viadocker exec tradein-postgres psql, both dupes are STILL present:Root cause
Deploy runs
for f in $(ls *.sql | sort); do psql < $f; doneon every push (idempotent ops). Sort order intradein-mvp/backend/data/sql/:End state of every deploy: dupes restored.
Fix
Remove the offending
CREATE INDEX IF NOT EXISTSstatements from migration 050 at the source. Replace them with breadcrumb comments pointing to the canonical indexes in earlier migrations (009_houses.sqland028_matching_tables.sql).Migration 035 retained as the durable DROP guard — on next deploy it drops the existing dupes, and 050 no longer recreates them. Steady-state then matches PR #500's original intent.
Diff stats
Test plan
docker exec tradein-postgres psql -U tradein -d tradein -c "\di+ listing_sources_*"shows_listing_idxonly (no_idx2).\di+ houses_geom_*—houses_geom_idxonly.listings_geom_active_idx,listings_active_filter_idx,listings_search_mv_*etc).Deep Code Review — verdict: APPROVE
Summary
CREATE INDEX IF NOT EXISTSfrom050_search_optimization.sqlto close the PR #500 regression loopClaim verification (all confirmed)
listing_sources_listing_idxis canonical in028_matching_tables.sql:71(btree onlisting_id) — single-column, exact duplicate of removed_idx2.houses_geom_idxis canonical in009_houses.sql:58(GIST on geom, non-partial) — strictly redundant with removed_idx2.035_drop_duplicate_indexes.sqldrops both_idx2variants viaDROP INDEX IF EXISTS(idempotent).028 → 035 → 050confirmed via repo listing — alphanumeric sort puts 035 strictly before 050. Steady state after this PR: 028 creates canonical → 035 drops dupes (no-op on subsequent runs) → 050 no longer recreates them. Production dupes vanish on next deploy.Idempotency / transactional safety
BEGIN; ... COMMIT;blocks (indexes + matview) intact.CREATE INDEX IF NOT EXISTSpreserved → file re-run safe.deploy-tradein.ymlrunsfor f in $(ls *.sql | sort); do psql -v ON_ERROR_STOP=on < $f; done— sort + ON_ERROR_STOP both honored. No deploy script changes needed.Regression check
listing_sources_listing_idx2|houses_geom_idx2→ only050(being removed) and035(dropping). Zero code references — no query, service, or test depends on the_idx2names.tradein-mvp/scripts/probe-migration-028.py:21checks for canonicallisting_sources_listing_idxonly — unaffected._idx2-suffixed indexes in 050 (listing_sources_price_divergence_idx2,houses_fingerprint_idx2,houses_kadastr_idx2) are NOT removed and NOT dropped by 035 — confirmed they're unique (no canonical equivalent in earlier migrations). Suffix is just legacy naming, not duplicate. Correct call to leave them alone.Architecture / archaeology
CREATE INDEXlines with breadcrumb comments pointing to028_matching_tables.sqland009_houses.sqlis the right call — future readers won't be confused why 050 "skips" indexes 8 and 10. Good hygiene.Tiny nit (non-blocking)
Risk / reversibility
009.houses_geom_idx,028.listing_sources_listing_idx) cover the same access paths.housesandlisting_sourcestables).