Skip to content

Conversation

@brianpursley
Copy link
Contributor

@brianpursley brianpursley commented Feb 1, 2026

Adds NpgsqlMigrationsAnnotationProvider to implement ForRemove(IRelationalModel).

Fixes #3604

…when migration is reverted.

Adds NpgsqlMigrationsAnnotationProvider to implement ForRemove(IRelationalModel).

Fixes npgsql#3604
Fixes npgsql#3183
Fixes npgsql#2514
Copilot AI review requested due to automatic review settings February 1, 2026 16:52
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

This PR ensures that provider-specific PostgreSQL annotations added to the model (enums, ranges, extensions, collations) are surfaced to EF Core’s migrations pipeline for removal when a migration is rolled back, fixing missing DROP operations for these objects.

Changes:

  • Introduces NpgsqlAnnotationHelper.IsRelationalModelAnnotation to centralize detection of model-level PostgreSQL relational annotations (extensions, enums, ranges, collation definitions).
  • Adds NpgsqlMigrationsAnnotationProvider and wires it into DI so ForRemove(IRelationalModel) returns the relevant PostgreSQL annotations used to generate DROP statements on migration rollback.
  • Refactors NpgsqlAnnotationProvider.For(IRelationalModel, bool) to reuse the new helper and adds tests verifying ForRemove behavior and annotation filtering.

Reviewed changes

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

Show a summary per file
File Description
src/EFCore.PG/Metadata/Internal/NpgsqlAnnotationHelper.cs Adds a reusable helper to identify Npgsql relational model annotations (extensions, enums, ranges, collations) by their annotation name prefixes.
src/EFCore.PG/Metadata/Internal/NpgsqlAnnotationProvider.cs Updates the For(IRelationalModel, bool) override to use NpgsqlAnnotationHelper.IsRelationalModelAnnotation, keeping behavior while centralizing the prefix logic.
src/EFCore.PG/Migrations/Internal/NpgsqlMigrationsAnnotationProvider.cs Implements a migrations annotation provider whose ForRemove(IRelationalModel) returns the Npgsql relational model annotations so that rollback migrations can drop associated database objects.
src/EFCore.PG/Extensions/NpgsqlServiceCollectionExtensions.cs Registers IMigrationsAnnotationProviderNpgsqlMigrationsAnnotationProvider in the provider’s service collection so EF Core uses the new provider during migrations.
test/EFCore.PG.Tests/Migrations/NpgsqlMigrationsAnnotationProviderTest.cs Adds unit tests verifying that ForRemove returns only the expected Npgsql relational model annotations and handles the no-annotations case correctly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

Thanks - this looks good, just one comment on the test.

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 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@brianpursley brianpursley requested a review from roji February 2, 2026 02:01
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

Thanks for contributing this!

@roji roji enabled auto-merge (squash) February 2, 2026 10:43
@roji roji merged commit ab2f0a6 into npgsql:main Feb 2, 2026
15 of 16 checks passed
@brianpursley brianpursley deleted the efcorepg-3604 branch February 2, 2026 14:31
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.

Model-level objects (extensions, enums, collations...) not getting dropped in Down migrations

2 participants