Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 25, 2025

Fixes #35016

Description
When creating an initial migration with database-level annotations like HasDatabaseMaxSize("10"), the generated migration correctly includes the annotation in the Up() method but omits it from the Down() 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 necessary OldAnnotation 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 missing AlterDatabase().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 in SqlServerModelDifferTest 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.

Remove exclusion of EditionOptions from SqlServerMigrationsAnnotationProvider.ForRemove() method.
This allows database-level annotations like HasDatabaseMaxSize to be properly included in the
Down() method of initial migrations.

Co-authored-by: AndriySvyryd <[email protected]>
@Copilot Copilot AI changed the title [WIP] Model annotation changes absent from Down() method of initial migration Fix EditionOptions missing from Down() method in initial migrations Aug 25, 2025
Copilot finished work on behalf of AndriySvyryd August 25, 2025 23:20
@Copilot Copilot AI requested a review from AndriySvyryd August 25, 2025 23:20
@AndriySvyryd AndriySvyryd changed the title Fix EditionOptions missing from Down() method in initial migrations [rc2] Fix EditionOptions missing from Down() method in initial migrations Aug 25, 2025
@AndriySvyryd
Copy link
Member

@copilot Rewrite the PR summary using this template:

Fixes #{number}

**Description**
{Issue description}

**Customer impact**
{How does the reported issue affects customer's app? Are there workarounds?}

**How found**
{Was it customer reported or found during verification? How many customers are affected?}

**Regression**
{Is it a regression from a released version? Which one?}

**Testing**
{How the changes were tested}

**Risk**
{Low/Medium/High, argument why}

Copy link
Contributor Author

Copilot AI commented Aug 25, 2025

@copilot Rewrite the PR summary using this template:

...

Updated the PR description using the requested template format.

Copilot finished work on behalf of AndriySvyryd August 25, 2025 23:38
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 annotation changes absent from Down() method of initial migration

2 participants