Skip to content

Make replace_index check independent of live database state - #92

Merged
fatkodima merged 1 commit into
fatkodima:masterfrom
camallen:remove-index-check-improvements
Jun 18, 2026
Merged

Make replace_index check independent of live database state#92
fatkodima merged 1 commit into
fatkodima:masterfrom
camallen:remove-index-check-improvements

Conversation

@camallen

Copy link
Copy Markdown
Contributor

Failure mode: The check that catches an unsafe same-name remove→add of an index in one migration only fires if the live connection can resolve the removed index. remove_index records into @removed_indexes only when the index physically exists, and add_index skips the check when that's empty. So a name-only remove_index/add_index pair passes silently whenever the index is missing locally (schema drift), the author never sees it before merge.

This PR Fix: Record every removal (falling back to the migration's declared options when the DB has no match), and match removed-vs-added indexes on name in intersect? the one identifier present in both calls. The check is now driven by the migration's own commands, not DB state.

Notes: Name match is only used in the removed-vs-new comparison, so other callers are unaffected. Legit same-name drop-and-rebuild migrations will now raise (correctly. same no-index window); safety_assured { } is the escape hatch. Added tests for the missing-index regression, distinct-name non-matching, and safety_assured.

The replace_index check only fired when the live connection could resolve
the removed index at check time: remove_index recorded into @removed_indexes
only when the index physically existed, and add_index skipped the check
entirely when that collection was empty.

This meant a same-name remove_index/add_index pair in a single migration
(the unsafe drop-then-rebuild pattern the check exists to stop) passed
silently whenever the index was missing from the connection (schema drift,
or a name-only removal whose columns cannot be resolved without the DB).

Record every removal, falling back to the migration's declared options
(which always include the name) when the connection has no matching index,
and match removed-vs-added indexes on name so the check is driven by the
migration's own commands rather than live database state.
@fatkodima
fatkodima force-pushed the remove-index-check-improvements branch from 8c132ca to 092fdb6 Compare June 18, 2026 17:00
@fatkodima
fatkodima merged commit b112627 into fatkodima:master Jun 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants