镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Drop removed database-level annotations after table and column operations - #39666

Open
seragAhmed wants to merge 1 commit into
dotnet:mainfrom
seragAhmed:fix/39563-alter-database-removals-after-columns
Open

seragAhmed wants to merge 1 commit into
dotnet:mainfrom
seragAhmed:fix/39563-alter-database-removals-after-columns

Conversation

@seragAhmed

@seragAhmed seragAhmed commented Nov 15, 2026 •

Copy link
Copy Markdown
  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

MigrationsModelDiffer.Sort now splits an AlterDatabaseOperation when it removes annotations. The removed annotations go into a second AlterDatabaseOperation (old annotations only, no new ones), which runs after the column, alter and obsolete-sequence operations. Additions, changes and the collation change stay in the original operation, in its usual place before the table operations. If nothing is left in the original operation, only the removal operation is emitted.

This way, providers drop a database object, such as an Npgsql collation, enum or extension, only after the columns that used it have been reverted. That applies to both Down() and Up(). The removal operation carries no new annotations, so SQL Server doesn't re-emit edition options or the memory-optimized setup for it.

Tests (in SqlServerModelDifferTest, which has real database-level annotations):

  • Removed_database_annotations_are_dropped_after_column_operations
  • Database_annotation_removals_are_split_from_other_database_changes
  • Alter_table_MemoryOptimized: in Down, the database-level MemoryOptimized removal now comes after the AlterTableOperation. SQL Server generates no SQL for that removal.

Fixes #39563

…ions

- In MigrationsModelDiffer.Sort, move annotations removed by an AlterDatabaseOperation into a separate AlterDatabaseOperation that runs after the column, alter and obsolete sequence operations
- Additions, changes and the collation change stay in the original operation, which keeps its place before the table operations
- This fixes Down() (and Up()) dropping a database object, such as an Npgsql collation, before reverting the columns that use it

Fixes dotnet#39563

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrations: Down() drops a database-level object (Npgsql collation) before reverting the columns that use it

1 participant