Skip to content

SQLite: refuse NULLS-ordered and expression parts the core cannot render (#134) - #140

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/134-sqlite-parts-refusal
Oct 20, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/134-sqlite-parts-refusal

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #134

Problem

On SQLite, which no satellite serves, a complex index with a DbOrder.NullsFirst/NullsLast part or an expression part was diffed by the core differ. That routes the index through the IndexParts annotation and appends the Npgsql sentinel (__requires_UseNpgsqlComplexIndexes__) to Columns. Only the PostgreSQL satellite's generator reads that annotation. On SQLite the sentinel was supposed to make the apply fail, but that held only with SQLite's double-quoted string literals off, as in the e_sqlite3 build Microsoft.Data.Sqlite bundles. With them on (SQLITE_DBCONFIG_DQS_DDL, the default in a stock SQLite build), the sentinel and a quoted expression are read as string literals, and the index applies with a constant column, without its ordering or expression:

CREATE UNIQUE INDEX "ux_nulls" ON "M" ("Email_V", "__requires_UseNpgsqlComplexIndexes__");
-- DQS off: no such column        DQS on: applied

The expression case was not in the issue. The fix's own revert run showed it: HasExpressionIndex, in a model shared with SQLite tests, applies silently the same way.

Change

  • CustomMigrationsModelDiffer.ValidateRenderableParts: runs on the target model only, when no satellite serves the provider. It refuses any index whose parts need the annotation, naming the index, the table and the provider, with the same remedies the SQL Server satellite gives. The source model is not checked, so a snapshot holding such an index stays diffable: removing the marker drops the index and creates it from its columns.
  • Tests that pinned the old answer: MigrationModelDifferTests checked the core differ's parts handling (NULLS ordering, expression parts) on SQLite. They now run the core differ over PostgreSQL, where those parts remain valid.
  • Changelogs: a row under ### Changed answers, in the Indexes area, in both the root and core changelogs.
  • Docs: a new entry under "Changed answers in 5.5.0" in docs/upgrading.md, saying how to find and fix an index that already applied this way. The core README and CLAUDE.md are updated too.

Tests

SqliteNullOrderingTests runs on real in-memory SQLite with SQLITE_DBCONFIG_DQS_DDL on:

  • A NULLS FIRST single-column index, a composite index with a NULLS LAST part, and an expression index are each refused before anything applies.
  • A database that already applied the index with its constant column is fixed by the next migration: drop, then create from the columns alone, verified against sqlite_master.

With ValidateRenderableParts reverted, the three refusal tests fail with "no exception was thrown": the migration applies silently. The snapshot test passes either way, on purpose. It guards against extending the check to the source model, which would make an affected snapshot impossible to diff.

The unit suite passes: 562 tests (TestCategory!=Integration&TestCategory!=SqlServer).

🤖 Generated with Claude Code

… satellite (#134)

Only the PostgreSQL satellite's generator renders the parts annotation. On
SQLite the index carried the Npgsql sentinel column, which fails only while
double-quoted string literals are off: with them on, the sentinel and a quoted
expression were taken for strings and the index applied with a constant
column. The core differ now refuses such a declaration in the target model
when no satellite serves the provider; a snapshot holding one stays diffable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 5.5.0 milestone Oct 20, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working silent Answers wrongly without throwing — fixes go in the next major, never deferred severity/low Cosmetic, message or documentation-level difference package/core Affects EFCore.ComplexIndexes area/indexes Complex-property, composite, unique and filtered indexes labels Oct 20, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 5a566bb into main Oct 20, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/134-sqlite-parts-refusal branch October 20, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/indexes Complex-property, composite, unique and filtered indexes bug Something isn't working package/core Affects EFCore.ComplexIndexes severity/low Cosmetic, message or documentation-level difference silent Answers wrongly without throwing — fixes go in the next major, never deferred

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQLite: a NULLS-ordered complex index scaffolds the PostgreSQL sentinel, and applies without its ordering where SQLite accepts double-quoted strings

1 participant