Repository navigation
Refuse an INCLUDE entry that names no column of the table - #147
Merged
Merged
Conversation
ResolveIncludeList passes an entry that names no property through verbatim as a column name. When the property an entry named was removed, both sides of the diff resolved to the same text, no index operation was emitted, and the migration was a bare DROP COLUMN: PostgreSQL dropped the unique index with the column and applied cleanly, SQL Server failed with Msg 5074. In the target model only, each entry of the diffed provider's INCLUDE list must now name a column of the index's table, compared by the provider's identifier rule. The verbatim fallback for a real column keeps working, and a snapshot holding such an entry stays diffable. 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 #142
Problem
ResolveIncludeListresolves each INCLUDE entry as a property path and falls back to the entry verbatim. WithHasComplexIndex(x => x.Email.Value, ix => ix.HasName("ux_email").IsUnique().IncludeProperties("Note"))and thenb.Ignore(x => x.Note), both sides of the diff resolved toNote, no index operation was emitted, and the migration was justALTER TABLE members DROP COLUMN "Note". PostgreSQL dropped the unique index with the column and applied cleanly; the snapshot still listed it, so nothing recreated it. SQL Server failed at apply (Msg 5074).Change
CustomMigrationsModelDiffer.ValidateIncludedColumns: target model only, each entry of the diffed provider's INCLUDE list (Npgsql:IndexInclude,SqlServer:Include) must name a column of the index's table, compared by the provider'sIndexNameComparer(ordinal on PostgreSQL, case-insensitive on SQL Server). Otherwisemigrations addthrows, naming the entry, index and table. Runs afterValidateNoSatelliteOptions, so the core differ on SQL Server/PostgreSQL still reports the missing satellite first, and only the diffed provider's list is checked (a model shared with SQLite carries options SQLite ignores).NpgsqlAnnotationForwardingTests'raw_colfixture named no column at all, so it now maps a shadow property toraw_col.EnsureCreated(),GenerateCreateScript()andMigrate()'s pending-changes check, so those now fail on such a model too. That is documented.### Changed answersrow in the root and the three package changelogs; newdocs/upgrading.mdentry, INCLUDE entries must name a column; a sentence indocs/sqlserver.mdandCLAUDE.md.Not covered here: a verbatim filter naming a removed column has the same shape.
ColumnsReadBymatches the table's column names inside the filter text. Finding a name the filter uses that is not a column would mean parsing SQL identifiers, so that case is noted on #142 rather than added to this PR.Tests
IncludeColumnValidationTests(12):NpgsqlDiffandSqlServerDiff, in both entity-level and property-level form, with no snapshot, and throughGenerateCreateScript()withUseNpgsqlComplexIndexes().raw_colnaming a real column (both providers),NOTEagainst columnnoteon SQL Server, a snapshot holding the bad entry diffing to a fixed model (both providers), removing the property and the entry together (drop index → drop column → create index), and SQLite ignoring both satellites' INCLUDE lists.Counterfactuals (verify-the-guard):
ValidateIncludedColumnscall removed, 4 tests fail with "Expected exception … but no exception was thrown": Npgsql entity-level, Npgsql property-level, SQL Server, and no-snapshot. TheGenerateCreateScripttest was added after this run.TestCategory!=Integration&TestCategory!=SqlServer) passes 581/581. I didn't run the integration suites locally; their INCLUDE entries are all real property paths.The snapshot, raw-column and SQLite tests guard against an over-strict check. They pass either way by design.
🤖 Generated with Claude Code