[rc2] Fix EditionOptions missing from Down() method in initial migrations #36649
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #35016
Description
When creating an initial migration with database-level annotations like
HasDatabaseMaxSize("10")
, the generated migration correctly includes the annotation in theUp()
method but omits it from theDown()
method. This inconsistency only affects initial migrations - subsequent migrations work correctly.Customer impact
Developers using database-level annotations (like SQL Server's
HasDatabaseMaxSize
,HasServiceTier
, etc.) in their models cannot properly rollback initial migrations. The Down() method lacks the necessaryOldAnnotation
calls to revert database-level changes. While the Down() method of initial migrations is rarely used in practice, this creates an inconsistent migration experience and prevents complete rollback scenarios. Workaround: Manually add the missingAlterDatabase().OldAnnotation()
calls to the Down() method.How found
Customer reported via GitHub issue #35016. This issue also affects other database providers (referenced in npgsql/efcore.pg#3183 and npgsql/efcore.pg#2514), indicating multiple customers are impacted.
Regression
No, this appears to be a long-standing behavior rather than a regression from a specific released version.
Testing
Added a comprehensive test case
Can_diff_model_annotations_with_initial_empty_model
inSqlServerModelDifferTest
that verifies both the presence of annotations in Up() operations and the proper inclusion of old annotations in Down() operations for initial migrations.Risk
Low. The change is surgical and minimal - it only removes a specific exclusion filter for EditionOptions annotations in the
SqlServerMigrationsAnnotationProvider.ForRemove()
method. This allows the normal annotation handling logic to include database-level annotations in Down() operations, matching the behavior of non-initial migrations. The change is isolated to the SQL Server provider and has comprehensive test coverage.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.