[release/5.0] SqlServer Migrations: Don't omit ALTER COLUMN when old type is unknown #23084
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 #23045
Description
In EF Core 5.0, we fixed issue #21364 which sometimes omitted the ALTER COLUMN statement when it was not needed. Unfortunately, migrations generated using versions of EF Core prior to version 3.1.0 don't contain enough information to always know whether or not the column type was actually changed. This results in the ALTER COLUMN statement being erroneously omitted.
Customer Impact
Anyone with migrations generated prior to EF Core 3.1 who try to apply them using EF Core 5.0 may run into this issue. Their column type will not be changed as expected which can lead to subsequent issues (as reported in the original issue).
How found
Customer reported
Test coverage
We have tests that cover migrations generated using EF Core 3.1 but they didn't cover this specific scenario. This PR adds additional coverage for it.
Regression?
Yes.
Risk
Low. This merely reverts to the behavior of previous versions (i.e. includes the ALTER TABLE statement) when the old column type is null/unknown.