Repository navigation
fix: compare index names the way each provider does (#116) - #127
Merged
Merged
Conversation
The core's name checks compared names ordinally, but SQLite folds the case of identifiers even when quoted, and SQL Server does under its default collation. Two complex indexes named "ix_case" and "IX_CASE", or a complex index named like a native one in another case, passed migrations add and failed at apply. CustomMigrationsModelDiffer.IndexNameComparer declares the provider's rule beside IndexNameScope: OrdinalIgnoreCase by default and on SQL Server, Ordinal on PostgreSQL, whose quoted identifiers keep their case. Both ValidateUniqueIndexNames and ValidateNoNativeIndexNameCollision compare under it, and their messages name both spellings. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two complex indexes named ix_case and IX_CASE on one table, refused at migrations add on a live SQL Server 2022, where an ordinal comparison let the second CREATE INDEX fail at apply. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CaffeinatedCoder
force-pushed
the
fix/116-index-name-case
branch
from
October 20, 2026 06:53
c4ee6b9 to
9a5a676
Compare
# Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #116
Problem
The core's index-name checks (
ValidateUniqueIndexNames,ValidateNoNativeIndexNameCollision) compared names ordinally. SQLite compares identifiers without regard to case even when they are quoted, and so does SQL Server under its default collation. Sopassed
migrations addand failed at apply. SQLite reportedindex IX_CASE already exists, and SQL Server 2022 reportedan index or statistics with name 'IX_CASE' already exists(from the probe on the #100 lane). A complex index named like a nativeHasIndexin another case failed the same way.Change
CustomMigrationsModelDiffer.IndexNameComparer(new, protected virtual) declares the provider's rule besideIndexNameScope. The core default isOrdinalIgnoreCase, for SQLite and for providers without a satellite. The SQL Server satellite declaresOrdinalIgnoreCaseexplicitly. The PostgreSQL satellite declaresOrdinal, because EF Core quotes every identifier and PostgreSQL keeps a quoted identifier's case. Ignoring case is the default for the same reason the widestIndexNameScopeis: a case-sensitive database pays a rename, while comparing ordinally approves a migration that fails at apply.ValidateNoKeyNameCollision) uses the same comparer instead of its ownOrdinalIgnoreCase, so SQL Server has one rule.### Fixed: root, core (SQLite) and SQL Server.### Added: the new hook.### Breaking: one narrow line. On a SQL Server database with a case-sensitive collation, or a provider without a satellite whose index names keep their case, such a pair applied and is now refused. That is why the PR and issue carrybreaking.docs/upgrading.mdhas the entry under "Upgrading to 5.5.0". README and CLAUDE.md state the rule.Tests
IndexNameCollisionTests:Sqlite_engine_rejects_index_names_differing_in_caseapplies the pair to a real SQLite through EF's generator. It shows the premise (index IX_CASE already exists) and passes with or without the fix.PostgresIntegrationTests.Index_names_differing_in_case_both_apply: the pair applies on PostgreSQL 18, and both indexes exist.SqlServerIntegrationTests.Index_names_differing_in_case_are_refused_before_apply(the lane row): two complex indexes namedix_caseandIX_CASEare refused atmigrations addon a live SQL Server 2022.proof/116-case-rule-reverted, which must never be merged, and dispatched the workflow there (run 39383024251). The lane row failed with the server's own refusal,SqlException: The operation failed because an index or statistics with name 'IX_CASE' already exists on table 'customers'.The four SQLite and SQL Server unit tests failed as well.🤖 Generated with Claude Code