Skip to content

Add KeysUniqueAcrossSchemas property to SharedTableConvention#37861

Merged
AndriySvyryd merged 6 commits intomainfrom
copilot/add-keys-unique-across-schemas
Mar 9, 2026
Merged

Add KeysUniqueAcrossSchemas property to SharedTableConvention#37861
AndriySvyryd merged 6 commits intomainfrom
copilot/add-keys-unique-across-schemas

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

When KeysUniqueAcrossTables is true, key constraint names are currently enforced unique across all tables regardless of schema. Databases like PostgreSQL scope constraint name uniqueness per-schema, so this produces unnecessary renames. See npgsql/efcore.pg#3704.

  • Add protected virtual bool KeysUniqueAcrossSchemas => true to SharedTableConvention, following the existing *UniqueAcrossTables property pattern
  • Group the table iteration in ProcessModelFinalizing by schema; clear the keys dictionary at schema boundaries when KeysUniqueAcrossSchemas is false
  • Order schema groups by schema name and tables within each group by table name for deterministic iteration
  • Default true preserves existing behavior; providers override to false as needed
  • Add SharedTableConventionTest with tests verifying both the override to false (keys not uniquified across schemas) and the default true behavior (keys uniquified across schemas), using the finalized model for assertions
// In a provider-specific convention (e.g. NpgsqlSharedTableConvention):
protected override bool KeysUniqueAcrossSchemas => false;

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Add a new protected virtual bool property KeysUniqueAcrossSchemas (default true)
that controls whether key constraint names must be unique across schemas.
Group the table iteration by schema and clear the keys dictionary at
schema boundaries when KeysUniqueAcrossSchemas is false.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Add KeysUniqueAcrossSchemas property to SharedTableConvention Add KeysUniqueAcrossSchemas property to SharedTableConvention Mar 5, 2026
Add SharedTableConventionTest with two tests:
- Keys_are_not_uniquified_across_schemas_when_KeysUniqueAcrossSchemas_is_false
- Keys_are_uniquified_across_schemas_when_KeysUniqueAcrossSchemas_is_true

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new KeysUniqueAcrossSchemas customization point to SharedTableConvention and introduces tests validating key name uniqueness behavior across schemas.

Changes:

  • Introduce SharedTableConvention.KeysUniqueAcrossSchemas (default true) to control key name uniqueness across schemas.
  • Update ProcessModelFinalizing to optionally reset key-name uniquification per schema.
  • Add tests covering both default behavior and KeysUniqueAcrossSchemas = false.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs Adds KeysUniqueAcrossSchemas and changes table iteration to support per-schema key uniquification.
test/EFCore.Relational.Tests/Metadata/Conventions/SharedTableConventionTest.cs Adds tests asserting key name behavior across schemas for both default and overridden convention behavior.

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
@AndriySvyryd AndriySvyryd marked this pull request as ready for review March 5, 2026 21:58
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner March 5, 2026 21:58
Copilot AI review requested due to automatic review settings March 5, 2026 21:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


You can also share your feedback on Copilot code review. Take the survey.

@AndriySvyryd AndriySvyryd merged commit 3781593 into main Mar 9, 2026
16 checks passed
@AndriySvyryd AndriySvyryd deleted the copilot/add-keys-unique-across-schemas branch March 9, 2026 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants