feat: detect and repair index definition drift during migrations #134
All Vouch review confidence checks passed
Residual risk 0.46 = Change Risk (0.79) × (1 − Review Confidence (0.42)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.79 · 221 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 10%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.323
No Reviewer Assigned
no_reviewer_assigned
0.120
Sensitive Paths
sensitive_paths
0.079
Real PR Conversation Timeline
1 comments
"Review active on #134"
general
weight: 0.35
jerenkrantz
Summary
Migrations()now detects when an existing index's definition has drifted from the expected state and automatically repairs itpg_indexes.indexdefas the source of truth, handling all index types (BTREE, GIN, BTREE_GIN, HNSW), UNIQUE indexes, WHERE predicates, override expressions, and partitioned tables (ON ONLY)Migration strategy
Uses a create-then-drop approach to avoid any window without an index:
1.
CREATE INDEX CONCURRENTLY IF NOT EXISTS "<name>_new" ...— builds the replacement index (non-blocking)2.
DROP INDEX CONCURRENTLY IF EXISTS "<name>"— removes the stale index (non-blocking)3.
ALTER INDEX "<name>_new" RENAME TO "<name>"— instant catalog-only renameCONCURRENTLYis used for non-partitioned tables (matching existing behavior viaindex2sql). This ensures queries always have at least one usable index during the transition.Drift detection only triggers when
index2expectedDef()produces a definition that differs from whatpg_indexes.indexdefactually stores — unchanged indexes are skipped with zero overhead.Test plan
pgQuoteIdent,pgNormalizeExpr,index2expectedDef,indexRename2sqlcovering all index types, partitioned tables, uppercase names, dropped/primary indexesTestMigrationIndexMutation— creates schema, introduces drift, verifies the 3-step CREATE/DROP/RENAME migration, and confirms convergence🤖 Generated with Claude Code