Repository navigation
fix(sqlserver): move complex indexes out of the way of ALTER COLUMN (#84) - #85
Merged
Merged
Conversation
) EF Core drops and re-creates its own indexes around an ALTER COLUMN on SQL Server; a complex index is not in EF's model, so it stayed, and SQL Server refused the statement with Msg 5074 ("The index 'ux_members_email' is dependent on column 'Email_Value'"). Any change of type, length or nullability of a column a complex index reads blocked deployment until the migration was edited by hand. The core differ gains a protected virtual, RequiresIndexRecreation: an unchanged complex index on a table whose base operations need it gone is dropped before them and created after them, like a changed one. It is off in the core; the SQL Server satellite turns it on for ALTER COLUMN on a column the index reads (key, INCLUDE, or named in the filter). PostgreSQL rebuilds such indexes itself. Verified on Azure SQL Edge: without the change the V1 -> V3 migration fails with Msg 5074, with it it applies. Reverting the source fails the new ordering test; the PostgreSQL and unrelated-column tests pin that nothing else moves. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 19, 2026
Keeps both protected overrides (RequiresIndexRecreation, ImplicitFilter) and both changelog entries. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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 #84
Problem
Changing the length, type or nullability of a column a complex index reads, on SQL Server, scaffolded a bare
ALTER TABLE [members] ALTER COLUMN [Email_Value] nvarchar(100) NOT NULL;, which SQL Server refuses:The index 'ux_members_email' is dependent on column 'Email_Value'(Msg 5074). EF drops and re-creates its own indexes around the statement; it does not know the complex index exists. Deployment stopped until someone edited the migration.Change
RequiresIndexRecreation(MigrationOperation, IReadOnlySet<string> columns). When it says so for a base operation on the index's table, an unchanged complex index is dropped before the base operations and created after them, the placement every changed index already gets. Off in the core. The columns are the key columns, every array-valued provider option (the INCLUDE list), and the table's columns that the filter or an expression part names.AlterColumnOperationon one of those columns.SQLite has the silent form of this problem (a table rebuild drops every complex index) and EF's SQLite generator emits rebuilds after all other operations, so this mechanism cannot fix it; that is tracked separately.
Tests
AlterColumnUnderIndexTests: on SQL Server,DropIndex→AlterColumn→CreateIndexfor a length change under the index; anALTER COLUMNon another column leaves the index alone; on PostgreSQL the same change emits no index operations.mssql/serverimage does not run on this arm64 host): the V1 → V3 migration fails with Msg 5074 onmainand applies with this change.🤖 Generated with Claude Code