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 #29902 - Renaming PeriodStart and PeriodEnd columns of a temporal table causes them to be swapped #32328

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,52 @@ protected virtual IEnumerable<MigrationOperation> Diff(
tm =>
string.Equals(sm.Property.Name, tm.Property.Name, StringComparison.OrdinalIgnoreCase)
&& EntityTypePathEquals(sm.Property.DeclaringType, tm.Property.DeclaringType, c))),
(s, t, _) => ColumnStructureEquals(s, t) && ColumnAnnotationsEqual(s, t, matchValues: true),
(s, t, _) => ColumnStructureEquals(s, t) && ColumnAnnotationsEqual(s, t, matchValues: false),
(s, t, _) => ColumnStructureEquals(s, t));

private static bool ColumnAnnotationsEqual(IColumn source, IColumn target, bool matchValues)
{
var sourceAnnotations = source.GetAnnotations().ToList();
var targetAnnotations = target.GetAnnotations().ToList();

if (sourceAnnotations.Count != targetAnnotations.Count)
{
return false;
}

foreach (var sourceAnnotation in sourceAnnotations)
{
var matchFound = false;
for (var i = 0; i < targetAnnotations.Count; i++)
{
var targetAnnotation = targetAnnotations[i];

if (sourceAnnotation.Name != targetAnnotation.Name)
{
continue;
}

if (matchValues && sourceAnnotation.Value != targetAnnotation.Value)
{
continue;
}

targetAnnotations.RemoveAt(i);
matchFound = true;

break;
}

if (!matchFound)
{
return false;
}
}

return true;
}

private static bool ColumnStructureEquals(IColumn source, IColumn target)
{
if (!source.TryGetDefaultValue(out var sourceDefault))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8429,7 +8429,7 @@ await Test(
""");
}

[ConditionalFact(Skip = "issue #29902")]
[ConditionalFact]
public virtual async Task Change_names_of_period_columns_in_temporal_table()
{
await Test(
Expand Down
Loading