Repository navigation
A column rename keeps the indexes and constraints on the column (#182) - #183
Merged
Merged
Conversation
#182 changes what a column rename scaffolds, so it ships in a minor. 5.5.1 had no change yet; its heading becomes 5.6.0 in the commit that adds the first entry. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The differs compared the source under its old column names and the target under the new ones, so every complex index, exclusion constraint and temporal constraint on a renamed column was dropped before the rename and created again after it, a full rebuild under an exclusive lock. PostgreSQL, SQL Server and SQLite all keep them through a rename. The source model is now resolved under the names the base RenameColumnOperations give its columns (ResolveSource, RenderedColumn). Only SQL this package renders from a column takes the new name: column parts, placeholders, JSON extractions, INCLUDE entries and the implicit SQL Server filter. Names still come from the source's own columns, so a default name that follows the column becomes a rename, as EF Core's do. Verbatim SQL is compared as written. Closes #182 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…umn it filters on CI's SQL Server lane showed sp_rename rejecting a column a filtered index's predicate reads: "The index 'ix_name_email_active' is dependent on column 'revoked_at'. RENAME COLUMN revoked_at failed because one or more objects access this column." A key or included column is renamed under the index. The in-the-way check now also passes the columns the filter names to an internal RequiresIndexRecreation overload, and the SQL Server differ drops such an index before a RenameColumnOperation of one of them and creates it after, the implicit IS NOT NULL filter included. EF Core rebuilds its own filtered indexes on a rename for the same reason. Refs #182 Co-Authored-By: Claude Opus 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 #182
Into
release/5.xdirectly: SchemaKit's differ is new code, anddesign/schemakit-api.md§9.4 needs the same rule (noted on #182).Closesacts only onmain, so #182 is closed by hand after the merge. The first commit opens 5.6.0 (5.5.1 had no entry yet), since a change to what a migration scaffolds ships in a minor.Problem
Renaming a column dropped every complex index, exclusion constraint and temporal constraint that read it before the
RENAME COLUMN, and created them again after it. PostgreSQL, SQL Server and SQLite all keep them through a rename, and EF Core emits only theRenameColumnOperationfor its own indexes. So a rename that should take milliseconds rebuilt each index under an exclusive lock held until commit.The differs compare resolved descriptors. The source resolved to the old column name and the target to the new one, so the pair never matched. Table renames were normalized; column renames were not.
Change
CustomMigrationsModelDiffer:ResolveSourceresolves the source model under the names the baseRenameColumnOperations give its columns, andRenderedColumnapplies them. The map is keyed by the source table: EF names the operation's table as the target has it, which the table-and-column test confirms. The new name reaches column parts, placeholders (filters and typed expressions), INCLUDE lists (ResolveIncludeColumns) and the implicit filter (RenderedImplicitFilter, which reads nullability from the source and renames the quoted columns in one pass). Default names still come from the source's own columns (ResolvedIndexPart.NameToken), so a default name that follows the column becomes aRenameIndexOperation, as EF Core's do. Verbatim SQL is compared as written.NameTokenfor default names), temporal constraints and temporal foreign keys. Source exclusion and temporal descriptors resolve insideResolveSource.ResolveIncludeColumns.sp_renamerejects a column that a filtered index's predicate reads (CI: "The index 'ix_name_email_active' is dependent on column 'revoked_at'"). So an internalRequiresIndexRecreationoverload also gets the filter's columns, and the SQL Server differ drops such an index before the rename and creates it after it, the implicitIS NOT NULLfilter included. EF Core rebuilds its own filtered indexes on a rename too. Key and included columns are renamed under the index.### Changed answers),docs/upgrading.md(Changed answers in 5.6.0), CLAUDE.md.Tests
ColumnRenameTests(unit). PostgreSQL with every declaration kind: only the fiveRenameColumnOperations, plus a rename of the default-named index and exclusion constraint. Table and columns renamed together. A real change beside the rename still drops before it and creates after it. A verbatim expression left unchanged gives no operation. SQL Server, with the implicitIS NOT NULLfilter and INCLUDE, and SQLite.PostgresIntegrationTests.Column_rename_keeps_indexes_and_constraints: applies the rename on PostgreSQL 18 and asserts every index's and constraint'spg_classOID is unchanged, so the objects were kept, not re-created under the same name. It also checks the definitions name the new columns.SqlServerIntegrationTests.Column_rename_keeps_the_indexes: on SQL Server 2022, the covering index survives the rename of its key and included columns, and the two filtered ones are rebuilt around it. The first push showed thesp_renamerejection; this lane runs only in CI (the image crashes locally without Rosetta).🤖 Generated with Claude Code