Repository navigation
A move into the default schema keeps the indexes and constraints on the table (#185) - #191
Merged
Merged
Conversation
… on the table EF Core writes the target's schema into RenameTableOperation.NewSchema, null for the default schema. The differs read null as "unchanged", so a table moved into the default schema was compared under its old schema and every complex index, exclusion constraint, temporal constraint and temporal foreign key on it was dropped and created again. On SQL Server that rebuilt each index although ALTER SCHEMA ... TRANSFER keeps them. On PostgreSQL, where Npgsql 10 writes nothing for that move, the creates named a table that was not there (42P01). NewSchema is now read as EF Core writes it in the three places that built renamed-table identities, as the SQLite rebuild path already did. Closes #185 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #185
Into
release/5.x.Closesacts only onmain, so #185 is closed by hand after the merge.Problem
Moving a table into the default schema (
ToTable("bookings", "north")→ToTable("bookings")) dropped and re-created every complex index, exclusion constraint, temporal constraint and temporal foreign key on it. EF Core writes the target's schema intoRenameTableOperation.NewSchema, sonullmeans the default schema (MigrationsModelDiffer:NewSchema = target.Schema). The differs readnullas "unchanged" (NewSchema ?? Schema), compared the source under its old schema, and matched nothing.ALTER SCHEMA … TRANSFERkeeps them.NewSchemaisnull(Generate(RenameTableOperation, …)checksNewSchema is not null), so the table stays in its schema. The creates then named a table in the default schema that doesn't exist.Change
NewSchemais now read as EF Core writes it in the three places that build renamed-table identities:CustomMigrationsModelDiffer.GetDifferences,SourceColumnRenames(so #182's column-rename fix covers such a table too), and the Npgsql differ'sBuildRenamedTables. The SQLite rebuild path already read it that way.PostgreSQL stays on Npgsql's behaviour. The migration now runs, and the table stays in its old schema, as it does without this package.
docs/upgrading.mdsays to name the schema (ToTable("bookings", "public")) to actually move it. Reporting that no-op to npgsql/efcore.pg is your call.Also: a
### Changed answersrow in all four changelogs, adocs/upgrading.mdentry, CLAUDE.md, andToTableadded toDocumentationApiTests.ExternalApi.Tests
SchemaMoveTests:RenameTableOperation. The model has an exclusion constraint, a temporal constraint, and a temporal FK whose principal moves.PostgresIntegrationTests.Move_into_default_schema_applies(PostgreSQL 18): the migration runs, and the index and exclusion constraint keep their OIDs.SqlServerIntegrationTests.Move_into_default_schema_keeps_the_indexes(CI only): no index operations, and the index exists after the transfer.42P01: relation "sm_bookings" does not exist). The two moves that already worked pass either way, on purpose.🤖 Generated with Claude Code