Repository navigation
Description
Decided 2026-11-25 with #115: refuse at the diff. In PR #194 (fix/145-sqlite-rebuild-refusal). Offline: 763 of the kernel's tests, 199 of the PostgreSQL package's, 90 of the second provider's. Live: 4 and 76 on PostgreSQL 16 and on 18, 86 on SQL Server 2022, the consumer smoke test's 47 rows. The live suites and the smoke test ran before the last test was added; nothing under src/ changed after them.
What is there:
- A create of an object on a table the same migration rebuilds is refused where the migration is scaffolded, with the declaration and the table named. An object is on a table when it reads a column of it or holds SQL written by hand, which is how the planner ties an object to a table everywhere else.
- The refusal names the way round it, and that way is measured: the declaration taken out, the table changed, the declaration put back, a migration each (
In_three_migrations_the_table_is_changed_and_the_index_is_there). - The seven tests of
SqliteExpressionIndexTeststhat held today's outcomes, four failures at apply and three silent losses, hold the refusal and that the database is not touched. The kernel'sOn_sqlite_an_index_lost_to_a_rebuild_is_refused_at_the_diffholds the same, and that the same two models on Npgsql are oneAlterColumnOperationand no refusal. - Only creates are refused. An object whose contributor answers that the rebuild leaves it alone is the contributor's word (
Answered_as_unaffected_the_rebuild_takes_the_index_without_a_word, unchanged).
Found on the way: #193, a fourth way into the same loss, fixed on this branch. A rebuild whose operation stands before the table's rename named the table as it was, the planner did not connect it with the objects on the table, wrote nothing, and the migration applied without the index.
The first form of the refusal had three parts no test held. Two were redundant and are gone: the check that the provider is SQLite, since only SQLite's operations are read as rebuilds, and an object's scope as a tie to its table. The third was the rule #193 is about.
Four rules were changed in turn and a test failed for each:
| Changed | Fails |
|---|---|
| No refusal | the kernel's test and eight of the second provider's |
| A rebuild names its table as its operation does (#193) | A_rebuild_written_for_the_table_under_its_old_name_is_refused_too |
| A column an object reads does not tie it to the table | the kernel's test and eight of the second provider's |
| Hand-written SQL does not tie an object to the table | An_index_of_hand_written_sql_on_the_rebuilt_table_is_refused, added after the run showed nothing held it |
The refusal goes when the generator decorator places the create behind the rebuild (#115, slice D).
Found by the SQLite probe of #119 on main @ 1690320 (EF Core 11.0.0-rc.3, a database file per test).
What happens
SQLite's generator moves a table rebuild to the end of the migration, behind every statement that follows the operation it was written for (plan 3.12, #65). What is known and held by On_sqlite_an_index_lost_to_a_rebuild_fails_the_migration_and_is_not_lost_in_silence: an object both models declare unchanged is created again before the rebuild, and the create fails on the object that is still there. That is loud.
When the name the create takes is free at that moment, nothing fails. The create runs on the old table, the rebuild drops the old table and the object with it, and the migration applies. Three ways to get there, each measured:
| The migration | What the planner writes | Outcome |
|---|---|---|
declares a new object and alters a column of its table (Email becomes required) |
AlterColumnOperation, CREATE INDEX … |
applies, no index |
| renames an object and alters a column of its table | AlterColumnOperation, CREATE INDEX "new" … (Lost decides before Plan, so nothing drops the old name) |
applies, no index under either name |
leaves the object alone, and its contributor answers RebuildAround to TableRebuilt |
DROP INDEX …, AlterColumnOperation, CREATE INDEX … |
applies, no index |
The first needs no answer of a contributor at all: the object is not on the source side, so ImpactOf is not asked. What the generator runs for it:
CREATE INDEX "IX_people_lower_name" ON "People" (lower("Name"));
CREATE TABLE "ef_temp_People" (…);
INSERT INTO "ef_temp_People" (…) SELECT … FROM "People";
PRAGMA foreign_keys = 0;
DROP TABLE "People";
ALTER TABLE "ef_temp_People" RENAME TO "People";
PRAGMA foreign_keys = 1;The snapshot holds the declaration afterwards, so no later diff sees the object missing.
A renamed table is the same case more often than it looks: by convention the primary key's name follows the table's (PK_People to PK_Persons), EF Core writes DropPrimaryKey and AddPrimaryKey beside the RenameTable, and SQLite rebuilds the table for both.
Whose it is
The kernel's. No package ships a contributor for SQLite, and CLAUDE.md says not to ship one before the generator places the create, which is why this is severity/medium: today a contributor of a third party or of a test reaches it. The contract is public, though, and nothing in it says that RebuildAround is an answer SQLite cannot take.
Change, to decide
Until the generator decorator places a create after the rebuild (plan 3.12; #115, point 4): refuse at the diff. On SQLite, a create of an object attached to a table that the same migration rebuilds is an error that names the declaration and the operation. That makes one refusal at migrations add of the three silent cases and of the loud one.
Test
SqliteExpressionIndexTests in test/CodoMetis.EFCore.SchemaKit.SecondProvider.Tests (#119) holds each row of the table as it is today, and each turns over with the fix.
Activity
test: a second provider against the public contract, on SQL Server 20…
test: a second provider against the public contract, on SQL Server 20…
test: what a seed of every line of the second provider still let through