Skip to content

The plan as ordered actions with a name ledger, not two lists around EF Core's operations #115

Open

Description

@CaffeinatedCoder

2026-11-25, where it stands. Slice A is merged: #145 and #193, PR #194. Slice B is in PR #196 (#195). Slice C, one ordered list with EF Core's operations, is at the gate of rc.1; slice D, a create behind SQLite's rebuild, comes with the first object SchemaKit creates on SQLite. Whether the row guard creates its trigger on SQLite in 11.0.0 is open on #47. This issue stays open for C and D.


Decided 2026-11-25 by the maintainer: the proposal below, as recommended. A and B for preview.2; Dependency.SchemaObject gains the object's scope; C moves to the gate of rc.1; D comes with the first object SchemaKit creates on SQLite. Whether the row guard creates its trigger on SQLite in 11.0.0 was not answered and stays open on #47. A is #145; B is a sub-issue of #111.


Proposal, 2026-11-25. A sentence that says "measured" names where; everything else is a recommendation. It proposes less than the issue below asks for, and says why.

Where the two lists stand today

A plan is Before and After, spliced around EF Core's operations. Of the four failures the issue names:

Failure Today
A name freed by a rename is free too late (#99) Fixed for preview.1 by a point fix: such a rename is a rebuild (KeepInPlace). Correct on PostgreSQL 16 and 18 (RenameInPlaceTests, the live pair). The cost is a rebuild where a rename would do
A create placed before tables precedes its schema Still so. Measured today with the kernel's sample domain on a table in a new schema: CREATE DOMAIN depot.weight AS integer;, then EnsureSchemaOperation, then CreateTableOperation. Nothing that ships is placed before tables
The order Dependency.SchemaObject promises is not kept Still so: creates are ordered by placement and then by the model's order. The dependency holds an owner and a name and no scope, so it cannot say which table's object it means (the second provider's audit, A_dependency_on_an_index_cannot_say_which_tables_index_it_means)
SQLite's rebuild has no place a create can follow Still so, and silent in three cases (#145, held as they are by the three Today_… tests)

What EF Core does with an annotation on a SqlOperation is measured (spike D): migrations add writes it as .Annotation(…) on the migrationBuilder.Sql(…) call, the generator receives it in a script, an idempotent script and a bundle, and the migration's code is its only carrier. So it is a file format in consumers' repositories from the day it ships.

Proposed: four slices, and not all of them now

A. Refuse on SQLite what would be lost (#145). A create of an object attached to a table that the same migration rebuilds is refused at the diff, with the declaration and the operation named. One refusal in place of three silent losses and one failure at apply. No contract change. It goes when slice D places the create.

B. Order SchemaKit's own actions by Dependency.SchemaObject. A create comes after the creates of what it depends on and a drop before their drops, within the placement's phase; a cycle is refused with its members named. This needs the dependency to say which object it means: Dependency.SchemaObject gains the object's scope, (Owner, Scope, Name). That is a change to a case of a closed union of the contract, so it is the maintainer's decision. The row guard (#47), in the 11.0.0 milestone, is the first object that needs it: a trigger after its function.

C. One ordered list in place of two. The planner returns its statements interleaved with EF Core's operations, each with the names it takes and gives up, and the name check walks that list from the source's claims. First use: what is created before tables goes after the EnsureSchema of its schema. KeepInPlace becomes that walk and keeps its answer, a rebuild: moving a rename ahead of EF Core's operations would need the contributor to write its statement for the table as the source names it, which the contract does not ask today. Nothing public changes.

D. A statement that says what it is, and SQLite's create after the rebuild. Annotations on SchemaKit's SqlOperations (kind, object, whether it follows a rebuild), and the generator decorator moves such a create behind the rebuild. The annotations are permanent once a consumer's migration holds them.

What I recommend

Three questions for the maintainer

  1. Is the scope on Dependency.SchemaObject accepted (slice B)? Without it the order can only be kept among objects whose names are unique in the model.
  2. Does the row guard (RowGuard: delete guards as declared triggers, with one raise-only function #47) create its trigger on SQLite in 11.0.0? If so, D is part of 11.0.0 and its annotation format has to be decided with RowGuard: delete guards as declared triggers, with one raise-only function #47, and A is only an interim. If not, A is the answer for 11.0.0.
  3. May C move from "before preview.2" to the gate of rc.1?

Before preview.2; #99 gets a point fix for preview.1. From the architecture debate of 2026-11-14; not decided. Revises the fixed order of plan section 3.6.

Problem

A plan is two lists, before and after EF Core's operations, and the name claims of #96 read the end state. So a name freed by a rename is free too late (#99), a create placed before tables can precede its schema, the order Dependency.SchemaObject promises is not kept (#24), and SQLite's rebuild at the end of a migration has no place a create can follow (plan 3.12). Every one is about a moment within the migration, which the two lists cannot say.

Change, to decide

  1. Ordered actions instead of two lists: each action of SchemaKit's says which names it takes and releases and what it needs to exist. EF Core's operations keep their order and are read the same way, through the effect adapters.
  2. A name ledger: the ordered actions are run against the source's claims. A take on a name still held turns a rename into a rebuild, or is refused when no order works. It replaces the end-state check and is the same on every provider (sp_rename on SQL Server, one namespace per database on SQLite).
  3. Order by Dependency.SchemaObject with fully scoped identities, cycles refused.
  4. Whether a SchemaKit statement carries what it is (kind, object, claims) as annotations on its SqlOperation, so that the generator decorator can place it after SQLite's rebuild and a tool can explain a migration. To check first: what EF Core scaffolds of an annotation on a SqlOperation.

Done when

#99's pair and its mirror apply, a domain is created after its schema, and the ordering test of #24 holds on PostgreSQL and on the second provider.

Activity

  1. added this to the 11.0.0 milestone on Nov 14, 2026
  2. added
    enhancement
    package/core
    area/migrations
    on Nov 14, 2026
  3. CaffeinatedCoder commented on Nov 16, 2026

    @CaffeinatedCoder
    OwnerAuthor

    Point 4, "to check first: what EF Core scaffolds of an annotation on a SqlOperation": measured in spike D (#19, spikes/D.ScriptsAndBundles, 2026-11-16, EF Core 11.0.0-rc.3).

    EF Core writes it, and the migration carries it on every path.

    The annotations were put on the operations the kernel's planner built from a contributor's statement, the instances SchemaKitModelDiffer hands to EF Core (by reflection, since the kernel has no way to say it yet). They were read back by a generator standing where the provider's stands, inside SchemaKit's decorator, so it sees the list the decorator hands on.

    Npgsql SQL Server SQLite
    migrations add .Annotation(…) on migrationBuilder.Sql(…), in Up and in Down the same the same
    The snapshot and the designer file neither holds it neither neither
    migrations script: the generator receives the operation with all five, each with its type and value, under Script the same the same
    migrations script --idempotent the same, under Script, Idempotent the same no idempotent scripts
    A migrations bundle, applying the migration the same, under Default (PostgreSQL 18) the same (SQL Server 2022) the same
    A value with no C# literal (a record) migrations add fails and writes nothing the same the same

    What migrations add wrote for the five annotations (two strings, a string[], an int and a bool), sorted by name:

    migrationBuilder.Sql("CREATE INDEX ix_things_name ON \"Things\" (\"Name\");")
        .Annotation("Spike:AfterRebuild", true)
        .Annotation("Spike:Claims", new[] { "relation:ix_things_name", "index:Things.ix_things_name" })
        .Annotation("Spike:Kind", "create index")
        .Annotation("Spike:Object", "ix_things_name")
        .Annotation("Spike:Order", 3);

    The refusal of a value EF Core cannot write is EF Core's own: Cannot scaffold C# literals of type '…'. The provider should implement CoreTypeMapping.GenerateCodeLiteral to support using it at design time.

    What follows for the decision:

    • The migration's code is the only carrier. Nothing else holds the annotation, so its names and values become a file format in consumers' repositories, as permanent as the statement beside them. A migration scaffolded before the kernel wrote annotations has none, so whatever reads them has to work without.
    • Values are what EF Core has a C# literal for. A string, a string[], an int and a bool pass; a record does not. Kind, object and claims fit as strings and string arrays.
    • An annotation is also what tells SchemaKit's statement from another. The generator receives SqlOperations that are neither SchemaKit's nor the consumer's: EF Core's own for the history table (DO $EFHistory$ … on Npgsql, CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" on SQLite).
    • The generator is told how the migration is applied: MigrationsSqlGenerationOptions arrives with the operations. That is what An idempotent script cannot carry a statement with the transaction suppressed on PostgreSQL: the migration is recorded without its index #155 needs to refuse a statement with the transaction suppressed in an idempotent script, and the annotation is what lets it name the object.

    Not measured: SQLite's table rebuild itself. The generator inside the decorator receives the operations before SQLite's generator reorders them, so the annotations are there for the decorator to place a create; whether an annotated operation is then placed correctly is this issue's own work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/migrationsenhancementpackage/core

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions