Skip to content

feat: the planner reads EF Core's operations as BaseChanges, asks ImpactOf and acts on the answer - #66

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
feat/planner-base-changes
Nov 12, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
feat/planner-base-changes

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

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. Every MigrationOperation type of EF Core Relational and the three providers is mapped to a BaseChange or marked harmless. On SQLite an operation the provider rebuilds the table for is also TableRebuilt. An operation type outside the table is reported, and the planner refuses it when either model declares an object.
  • ImpactOf is 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.
  • The answer that asks most decides, before Plan is asked:
    • RebuildAround: dropped before EF Core's operations and created after them, also when both sides are equal. Refused for a BeforeTables contributor.
    • Lost: not dropped, and created after.
    • Follows and Unaffected: as before.

What the guards found while they were written

  • The operation table was incomplete: AlterDatabaseOperation+CreateDatabaseOperation, a nested type, was missing.
  • My SQLite rebuild list was wrong twice: a stored computed AddColumn is not a rebuild, and AlterTableOperation is one. The list is now what the provider's generator does, and a test asks the generator.
  • On SQLite a create after a rebuild runs before it. SQLite's generator moves a table rebuild to the end of the migration. The planner knows the rebuild and re-creates what the contributor reports as lost, but that create runs while the object is still there and fails with "index ux_name already exists". So the migration now fails to apply, where before it applied and lost the object. Placing the create after the rebuild is the generator decorator's work, which the plan's section 3.12 already owes; the finding is written there and in CLAUDE.md, and the live test holds today's behaviour so that it changes with the fix.

Not here (stays in #24)

  • Follows as 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.
  • Ordering by Dependency.SchemaObject; deleting the stand-in planner in Harness/TestKit.cs.
  • A way for another package to say what its own operation type does. Today such a migration is refused when the model declares an object.

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.

SchemaImpactTests drives 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:

Undone Fails
Unknown operation types are not collected / are let through the unknown-operation test (each)
An operation type missing from the table Every_operation_type_of_ef_core_and_the_providers_is_known
AlterColumn is not a rebuild on SQLite the generator test, the live SQLite test
AddColumn is a rebuild on SQLite the generator test, 3 rows
SQLite is not told apart the live SQLite test
A renamed table is another table A_change_on_a_renamed_table_reaches_the_object_that_names_the_old_one
A renamed column is another column A_change_to_a_renamed_column_reaches…, The_answer_that_asks_most_decides
A whole-table dependency reads no column the renamed-table test
Every change touches every object A_contributor_is_not_asked_about_a_column_its_object_does_not_read
An unchanged object is not rebuilt around An_unchanged_object_is_rebuilt_around_an_operation_that_cannot_run_while_it_exists
An unchanged object that is lost is not created again An_unchanged_object_the_operation_takes_away_is_created_again, the live SQLite test
A changed pair is always planned A_changed_object_is_not_planned_when_the_operation_decides and two more
Follows outweighs Lost The_answer_that_asks_most_decides
A rebuild around is allowed before the tables What_tables_are_made_of_cannot_be_rebuilt_around_an_operation

🤖 Generated with Claude Code

…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]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 12, 2026
@CaffeinatedCoder CaffeinatedCoder added enhancement New feature or request package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) area/migrations The differ and generator decorators, snapshot format, EnsureCreated and the UseSchemaKit wiring labels Nov 12, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 5bf0a0a into main Nov 12, 2026
6 of 7 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the feat/planner-base-changes branch November 12, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/migrations The differ and generator decorators, snapshot format, EnsureCreated and the UseSchemaKit wiring enhancement New feature or request package/core Affects CodoMetis.EFCore.SchemaKit (the kernel)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Planner, second slice: EF Core's operations as BaseChange, ImpactOf asked and acted on, and an unknown operation type refused

1 participant