Skip to content

fix: check index and constraint names against tables, views and sequences (#82) - #106

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/82-relation-namespace
Oct 20, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/82-relation-namespace

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Closes #82

Problem

PostgreSQL keeps index names unique among all relations of a schema: indexes, tables, views and sequences. ValidateNamesAcrossKinds and the schema-scoped index-name check only collected indexes and constraints, so

b.HasComplexIndex(x => x.Code, indexName: "codes");   // on table "rows", while a table "codes" exists

scaffolded cleanly and failed at apply with 42P07 relation "codes" already exists. An exclusion or temporal constraint (each owns an index) named like a view or sequence did the same.

Change

  • NpgsqlComplexIndexMigrationsModelDiffer.ValidateNamesAcrossKinds also adds the target model's tables, views (IRelationalModel.Views) and sequences (GetSequences()) to the per-schema relation namespace. As before, a collision is reported only when one side is this package's. Two of EF Core's own objects are left alone, and so is a temporal foreign key named like a table, since it owns no index.
  • The message names the relation itself ("has the same name as the table 'stays'"). The rule text adds that tables, views and sequences share the namespace.
  • NamedObject.IsIndexBacked is renamed InRelationNamespace to match what it now holds.
  • Prose: the root README's index-name paragraph and CLAUDE.md's ValidateNamesAcrossKinds section. One ### Fixed line goes into the root and PostgreSQL changelogs.

Not covered: the sequence PostgreSQL creates implicitly for an identity or serial column (bookings_Id_seq) is not in the model, so a complex index with exactly that name still fails at apply. Reaching it takes a deliberately odd name, so this PR leaves it alone; it is filed as #115.

Tests

  • NpgsqlNameCollisionTests: a complex index named like a table, an exclusion constraint named like a view, and a temporal constraint named like a sequence are each rejected, and the message names the relation. A temporal foreign key named like a table is accepted, and so is a complex index named like a table in another schema.
  • Seeded one at a time: dropping the tables from the check fails the table test, dropping the views fails the view test, dropping the sequences fails the sequence test, and ignoring the relation's schema fails the other-schema test.
  • Full suite, integration included: 403 passed.

🤖 Generated with Claude Code

…nces

ValidateNamesAcrossKinds put indexes and the constraints that own one into
PostgreSQL's per-schema relation namespace, but not the relations
themselves. A complex index named like another table of its schema, or an
exclusion or temporal constraint named like a view or sequence, scaffolded
and failed at apply with 42P07.

The model's tables, views and sequences now join the relation-namespace
check, still reported only when the other party is this package's.
Proven by seeding: dropping the tables, the views or the sequences from the
check each fails its own test, and ignoring their schema fails the
other-schema test.

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 severity/low Cosmetic, message or documentation-level difference package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL area/indexes Complex-property, composite, unique and filtered indexes area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints labels Oct 20, 2026
# Conflicts:
#	CHANGELOG.md
#	src/EFCore.ComplexIndexes.PostgreSQL/CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints area/indexes Complex-property, composite, unique and filtered indexes bug Something isn't working package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Index and constraint names are not checked against table, view and sequence names in the schema

1 participant