Skip to content

fix: compare index names the way each provider does (#116) - #127

Merged
CaffeinatedCoder merged 3 commits into
mainfrom
fix/116-index-name-case
Oct 20, 2026
Merged

CaffeinatedCoder merged 3 commits into
mainfrom
fix/116-index-name-case

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

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. So

b.HasComplexIndex(x => x.Contact.Phone, indexName: "ix_case");
b.HasComplexIndex(x => x.Contact.Email, indexName: "IX_CASE");

passed migrations add and failed at apply. SQLite reported index IX_CASE already exists, and SQL Server 2022 reported an index or statistics with name 'IX_CASE' already exists (from the probe on the #100 lane). A complex index named like a native HasIndex in another case failed the same way.

Change

Tests

  • IndexNameCollisionTests:
    • SQLite and SQL Server each reject both shapes: two complex indexes, and a complex and a native index.
    • PostgreSQL creates both indexes.
    • Sqlite_engine_rejects_index_names_differing_in_case applies 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.
  • Reverts:
    • With the checks keyed ordinally again (the bug), the four SQLite and SQL Server rejection tests fail.
    • With the PostgreSQL override removed, the PostgreSQL acceptance test fails.
  • Full suite, integration included: 439 passed.
  • SqlServerIntegrationTests.Index_names_differing_in_case_are_refused_before_apply (the lane row): two complex indexes named ix_case and IX_CASE are refused at migrations add on a live SQL Server 2022.
  • Proof on the lane: I reverted the case rule in a throwaway commit on 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

@CaffeinatedCoder CaffeinatedCoder added this to the 5.5.0 milestone Oct 20, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working breaking Changes an answer or a signature — needs a major severity/low Cosmetic, message or documentation-level difference package/core Affects EFCore.ComplexIndexes package/sqlserver Affects EFCore.ComplexIndexes.SqlServer area/indexes Complex-property, composite, unique and filtered indexes labels Oct 20, 2026
CaffeinatedCoder and others added 2 commits October 20, 2026 08:52
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
CaffeinatedCoder merged commit da2c9d5 into main Oct 20, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/116-index-name-case branch October 20, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/indexes Complex-property, composite, unique and filtered indexes breaking Changes an answer or a signature — needs a major bug Something isn't working package/core Affects EFCore.ComplexIndexes package/sqlserver Affects EFCore.ComplexIndexes.SqlServer severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Index names that differ only in case pass the name checks and fail at apply on SQL Server and SQLite

1 participant