Skip to content

An INCLUDE entry whose property was removed falls back to verbatim text, and PostgreSQL silently drops the index #142

Closed

Description

@CaffeinatedCoder

Found by a pre-release sweep of main @ 934ec55; reproduced in a scratch test.

Problem

ResolveIncludeList (CustomMigrationsModelDiffer.cs:698-707) resolves each INCLUDE entry as a property path and falls back to the entry verbatim (ResolveColumnName(...) ?? entry). When the property an entry named is removed from the model, the target resolves to the same text the source did. The descriptors are equal, and the index is left untouched.

Model: HasComplexIndex(x => x.Email.Value, ix => ix.HasName("ux_email").IsUnique().IncludeProperties("Note")). The next model adds b.Ignore(x => x.Note) and keeps the declaration. The whole migration is:

ALTER TABLE members DROP COLUMN "Note";
  • PostgreSQL: DROP COLUMN drops every index that uses the column, INCLUDE columns included. The unique index disappears, the migration applies cleanly, and the snapshot still lists the index, so no later migration recreates it.
  • SQL Server: the same migration fails at apply (Msg 5074).

The same applies to a verbatim filter that names the removed column (not reproduced).

Change

Keep the documented verbatim fallback ("raw_col"), but in the target model check each fallback entry against the table's columns and throw from migrations add, naming the entry, when no such column exists. ColumnsReadBy already matches filter text against the table's columns and could cover the filter case. This changes an answer (a model that scaffolded now fails), so it belongs under ### Changed answers with a docs/upgrading.md entry.

Tests

NpgsqlDiff and SqlServerDiff tests: the model above throws InvalidOperationException naming Note. A test that "raw_col" naming a real column still passes.

Activity

  1. added this to the 5.5.0 milestone on Oct 20, 2026
  2. added
    bug
    silent
    severity/high
    package/core
    package/postgresql
    package/sqlserver
    on Oct 20, 2026
  3. added
    area/indexes
    area/migrations
    on Oct 20, 2026
  4. CaffeinatedCoder commented on Oct 20, 2026

    @CaffeinatedCoder
    OwnerAuthor

    Fixed for INCLUDE entries in #147. The filter case is not part of that PR.

    Filter case. A verbatim filter that names a removed column (filter: "\"Note\" IS NOT NULL") has the same shape: both sides carry the same text, no index operation is emitted, and on PostgreSQL the DROP COLUMN takes the index with it. ColumnsReadBy can't cover it cleanly. It only checks which of the table's column names appear in the filter text, and that over-approximates. The check this case needs goes the other way: find a name the filter uses that is not a column. That means tokenizing SQL identifiers per provider (quoted "x" / [x] and unquoted ones, outside string literals), and telling columns apart from function names, keywords, casts and JSON path segments. A filter written with {Property} placeholders is already covered, because an unresolvable placeholder throws. Doing this for a verbatim filter needs its own design: either a quoted-identifier-only check, or steering users towards placeholders.

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/indexesarea/migrationsbugpackage/corepackage/postgresqlpackage/sqlserverseverity/highsilent

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions