Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to #35108 - Temporal table migration regression from EF Core 8 to 9 #35283

Merged
merged 1 commit into from
Dec 7, 2024

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Dec 6, 2024

In 9 we changed the way we process migration of temporal tables. One of the changes was drastically reducing the number of annotations for columns which are part of temporal tables. This however caused regressions for cases where migration code was created using EF8 (and containing those legacy annotations) but then executed using EF9 tooling. Specifically, extra annotations were generating a number of superfluous Alter Column operations (which were only modifying those annotations). In EF8 we had logic to weed out those operations, but it was removed in EF9.

Fix is to remove all the legacy annotations on column operations before we start processing them. We no longer rely on them, but rather use annotations on Table operations and/or relational model. The only exception is CreateColumnOperation, so for it we convert old annotations to TemporalIsPeriodStartColumn and TemporalIsPeriodEndColumn where appropriate. Also, we are bringing back logic from EF8 which removed unnecessary AlterColumnOperations if the old and new columns are the same after the legacy temporal annotations have been removed.

Fixes #35108
Also fixes #35148 which was the same underlying issue.

@maumar maumar requested a review from a team as a code owner December 6, 2024 11:53
@maumar maumar requested a review from Copilot December 6, 2024 11:53

Choose a reason for hiding this comment

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

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

case AlterColumnOperation alterColumnOperation:
RemoveLegacyTemporalColumnAnnotations(alterColumnOperation);
RemoveLegacyTemporalColumnAnnotations(alterColumnOperation.OldColumn);
if (!CanSkipAlterColumnOperation(alterColumnOperation, alterColumnOperation.OldColumn))
Copy link
Member

Choose a reason for hiding this comment

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

To be safe only call this if any annotations were removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's already the case - we short-circuit all operations that don't contain SqlServerAnnotationNames.IsTemporal set to true. For AlterColumnOperation (actually all column operations) IsTemporal is only set for legacy scenario

In 9 we changed the way we process migration of temporal tables. One of the changes was drastically reducing the number of annotations for columns which are part of temporal tables.
This however caused regressions for cases where migration code was created using EF8 (and containing those legacy annotations) but then executed using EF9 tooling.
Specifically, extra annotations were generating a number of superfluous Alter Column operations (which were only modifying those annotations). In EF8 we had logic to weed out those operations, but it was removed in EF9.

Fix is to remove all the legacy annotations on column operations before we start processing them. We no longer rely on them, but rather use annotations on Table operations and/or relational model.
The only exception is CreateColumnOperation, so for it we convert old annotations to TemporalIsPeriodStartColumn and TemporalIsPeriodEndColumn where appropriate.
Also, we are bringing back logic from EF8 which removed unnecessary AlterColumnOperations if the old and new columns are the same after the legacy temporal annotations have been removed.

Fixes #35108
Also fixes #35148 which was the same underlying issue.
@maumar maumar merged commit 8a918fc into main Dec 7, 2024
7 checks passed
@maumar maumar deleted the fix35108 branch December 7, 2024 04: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.

Rowversion migration regression from EF Core 8 to 9 Temporal table migration regression from EF Core 8 to 9
2 participants