Repository navigation
feat: the planner reads EF Core's operations as BaseChanges, asks ImpactOf and acts on the answer - #66
Merged
Conversation
…actOf and acts on the answer Every MigrationOperation type of EF Core Relational and the providers is mapped to a BaseChange or marked harmless; one outside the table is refused when a model declares an object. On SQLite an operation the provider rebuilds the table for is also TableRebuilt. For each object and each change that touches what it depends on, tables and columns carried forward through EF Core's renames, the contributor is asked ImpactOf. RebuildAround drops before and creates after also when both sides are equal; Lost creates again without a drop. Either decides before Plan. On SQLite the create after a rebuild runs before it, because the generator moves the rebuild to the end: the migration fails instead of losing the object in silence. The plan says what is owed. Closes #65 Co-Authored-By: Claude Fable 5.2 <[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 #65
The second slice of #24, which stays open.
Problem
The planner compared the declarations of two models and did not look at what EF Core does between them. An object both models declare unchanged was left alone, also when an operation of EF Core's removes it or cannot run while it exists. The first is the failure this package exists to prevent: a migration that applies cleanly and leaves the database without what the model declares.
Change
Migrations/Internal/BaseChanges.cs. EveryMigrationOperationtype of EF Core Relational and the three providers is mapped to aBaseChangeor marked harmless. On SQLite an operation the provider rebuilds the table for is alsoTableRebuilt. An operation type outside the table is reported, and the planner refuses it when either model declares an object.ImpactOfis asked for each source object and each change that touches what it depends on: a column it reads, the whole table, its scope. Tables and columns are carried forward through EF Core's renames, since EF Core names a later operation's table and column as the target has them.Planis asked:RebuildAround: dropped before EF Core's operations and created after them, also when both sides are equal. Refused for aBeforeTablescontributor.Lost: not dropped, and created after.FollowsandUnaffected: as before.What the guards found while they were written
AlterDatabaseOperation+CreateDatabaseOperation, a nested type, was missing.AddColumnis not a rebuild, andAlterTableOperationis one. The list is now what the provider's generator does, and a test asks the generator.CLAUDE.md, and the live test holds today's behaviour so that it changes with the fix.Not here (stays in #24)
Followsas more than "leave it": the source side resolved under a renamed table or column (with SchemaResolver: paths to columns and SQL, identically on both sides of a diff #43). Until then an object on a renamed table is dropped and created, and no contributor is asked about it; a test holds that.Dependency.SchemaObject; deleting the stand-in planner inHarness/TestKit.cs.Tests
Kernel tests without a server, on SDK 11.0.100 in the checkout: 343 before, 376 after. Probes: 125 pass. The PostgreSQL integration tests did not run locally; CI runs them.
SchemaImpactTestsdrives the real host: who is asked about which change, what each answer turns into, the unknown operation, the complete table, SQLite's rebuild list against its generator (19 operations), and the SQLite case on a live database file.Each rule undone in a scratch copy:
Every_operation_type_of_ef_core_and_the_providers_is_knownAlterColumnis not a rebuild on SQLiteAddColumnis a rebuild on SQLiteA_change_on_a_renamed_table_reaches_the_object_that_names_the_old_oneA_change_to_a_renamed_column_reaches…,The_answer_that_asks_most_decidesA_contributor_is_not_asked_about_a_column_its_object_does_not_readAn_unchanged_object_is_rebuilt_around_an_operation_that_cannot_run_while_it_existsAn_unchanged_object_the_operation_takes_away_is_created_again, the live SQLite testA_changed_object_is_not_planned_when_the_operation_decidesand two moreFollowsoutweighsLostThe_answer_that_asks_most_decidesWhat_tables_are_made_of_cannot_be_rebuilt_around_an_operation🤖 Generated with Claude Code