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

Temporal table migrations refactor. #32239

Merged
merged 1 commit into from
Nov 13, 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 @@ -84,11 +84,8 @@ public override void Generate(IColumn column, CSharpRuntimeAnnotationCodeGenerat
var annotations = parameters.Annotations;
annotations.Remove(SqlServerAnnotationNames.Identity);
annotations.Remove(SqlServerAnnotationNames.Sparse);
annotations.Remove(SqlServerAnnotationNames.IsTemporal);
annotations.Remove(SqlServerAnnotationNames.TemporalHistoryTableName);
annotations.Remove(SqlServerAnnotationNames.TemporalHistoryTableSchema);
annotations.Remove(SqlServerAnnotationNames.TemporalPeriodStartColumnName);
annotations.Remove(SqlServerAnnotationNames.TemporalPeriodEndColumnName);
annotations.Remove(SqlServerAnnotationNames.TemporalIsPeriodStartColumn);
annotations.Remove(SqlServerAnnotationNames.TemporalIsPeriodEndColumn);
}

base.Generate(column, parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,20 @@ public static class SqlServerAnnotationNames
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public const string UseSqlOutputClause = Prefix + "UseSqlOutputClause";

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public const string TemporalIsPeriodStartColumn = Prefix + "TemporalIsPeriodStartColumn";

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public const string TemporalIsPeriodEndColumn = Prefix + "TemporalIsPeriodEndColumn";
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override IEnumerable<IAnnotation> For(ITable table, bool designTime)
yield return new Annotation(SqlServerAnnotationNames.MemoryOptimized, true);
}

if (entityType.IsTemporal() && designTime)
if (entityType.IsTemporal())
{
yield return new Annotation(SqlServerAnnotationNames.IsTemporal, true);
yield return new Annotation(SqlServerAnnotationNames.TemporalHistoryTableName, entityType.GetHistoryTableName());
Expand Down Expand Up @@ -253,7 +253,7 @@ public override IEnumerable<IAnnotation> For(IColumn column, bool designTime)
}

var entityType = (IEntityType)column.Table.EntityTypeMappings.First().TypeBase;
if (entityType.IsTemporal() && designTime)
if (entityType.IsTemporal())
AndriySvyryd marked this conversation as resolved.
Show resolved Hide resolved
{
var periodStartPropertyName = entityType.GetPeriodStartPropertyName();
var periodEndPropertyName = entityType.GetPeriodEndPropertyName();
Expand All @@ -275,12 +275,14 @@ public override IEnumerable<IAnnotation> For(IColumn column, bool designTime)
? periodEndProperty.GetColumnName(storeObjectIdentifier)
: periodEndPropertyName;

// TODO: issue #27459 - we want to avoid having those annotations on every column
yield return new Annotation(SqlServerAnnotationNames.IsTemporal, true);
yield return new Annotation(SqlServerAnnotationNames.TemporalHistoryTableName, entityType.GetHistoryTableName());
yield return new Annotation(SqlServerAnnotationNames.TemporalHistoryTableSchema, entityType.GetHistoryTableSchema());
yield return new Annotation(SqlServerAnnotationNames.TemporalPeriodStartColumnName, periodStartColumnName);
yield return new Annotation(SqlServerAnnotationNames.TemporalPeriodEndColumnName, periodEndColumnName);
if (column.Name == periodStartColumnName)
{
yield return new Annotation(SqlServerAnnotationNames.TemporalIsPeriodStartColumn, true);
}
else if (column.Name == periodEndColumnName)
{
yield return new Annotation(SqlServerAnnotationNames.TemporalIsPeriodEndColumn, true);
}
bricelam marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,58 +32,19 @@ public override IEnumerable<IAnnotation> ForRemove(IRelationalModel model)
public override IEnumerable<IAnnotation> ForRemove(ITable table)
=> table.GetAnnotations();

/// <inheritdoc />
public override IEnumerable<IAnnotation> ForRemove(IUniqueConstraint constraint)
{
if (constraint.Table[SqlServerAnnotationNames.IsTemporal] as bool? == true)
{
yield return new Annotation(SqlServerAnnotationNames.IsTemporal, true);

yield return new Annotation(
SqlServerAnnotationNames.TemporalPeriodStartColumnName,
constraint.Table[SqlServerAnnotationNames.TemporalPeriodStartColumnName]);

yield return new Annotation(
SqlServerAnnotationNames.TemporalPeriodEndColumnName,
constraint.Table[SqlServerAnnotationNames.TemporalPeriodEndColumnName]);

yield return new Annotation(
SqlServerAnnotationNames.TemporalHistoryTableName,
constraint.Table[SqlServerAnnotationNames.TemporalHistoryTableName]);

yield return new Annotation(
SqlServerAnnotationNames.TemporalHistoryTableSchema,
constraint.Table[SqlServerAnnotationNames.TemporalHistoryTableSchema]);
}
}

/// <inheritdoc />
public override IEnumerable<IAnnotation> ForRemove(IColumn column)
{
if (column.Table[SqlServerAnnotationNames.IsTemporal] as bool? == true)
maumar marked this conversation as resolved.
Show resolved Hide resolved
{
yield return new Annotation(SqlServerAnnotationNames.IsTemporal, true);

yield return new Annotation(
SqlServerAnnotationNames.TemporalHistoryTableName,
column.Table[SqlServerAnnotationNames.TemporalHistoryTableName]);

yield return new Annotation(
SqlServerAnnotationNames.TemporalHistoryTableSchema,
column.Table[SqlServerAnnotationNames.TemporalHistoryTableSchema]);

if (column[SqlServerAnnotationNames.TemporalPeriodStartColumnName] is string periodStartColumnName)
if (column[SqlServerAnnotationNames.TemporalIsPeriodStartColumn] as bool? == true)
{
yield return new Annotation(
SqlServerAnnotationNames.TemporalPeriodStartColumnName,
periodStartColumnName);
yield return new Annotation(SqlServerAnnotationNames.TemporalIsPeriodStartColumn, true);
}

if (column[SqlServerAnnotationNames.TemporalPeriodEndColumnName] is string periodEndColumnName)
if (column[SqlServerAnnotationNames.TemporalIsPeriodEndColumn] as bool? == true)
{
yield return new Annotation(
SqlServerAnnotationNames.TemporalPeriodEndColumnName,
periodEndColumnName);
yield return new Annotation(SqlServerAnnotationNames.TemporalIsPeriodEndColumn, true);
}
}
}
Expand All @@ -102,37 +63,28 @@ public override IEnumerable<IAnnotation> ForRename(ITable table)
yield return new Annotation(
SqlServerAnnotationNames.TemporalHistoryTableSchema,
table[SqlServerAnnotationNames.TemporalHistoryTableSchema]);

yield return new Annotation(
SqlServerAnnotationNames.TemporalPeriodStartColumnName,
table[SqlServerAnnotationNames.TemporalPeriodStartColumnName]);

yield return new Annotation(
SqlServerAnnotationNames.TemporalPeriodEndColumnName,
table[SqlServerAnnotationNames.TemporalPeriodEndColumnName]);
}
}

/// <inheritdoc />
public override IEnumerable<IAnnotation> ForRename(IColumn column)
{
if (column.Table[SqlServerAnnotationNames.IsTemporal] as bool? == true)
if (column[SqlServerAnnotationNames.TemporalIsPeriodStartColumn] as bool? == true)
{
yield return new Annotation(SqlServerAnnotationNames.IsTemporal, true);

yield return new Annotation(
SqlServerAnnotationNames.TemporalHistoryTableName,
column.Table[SqlServerAnnotationNames.TemporalHistoryTableName]);

yield return new Annotation(
SqlServerAnnotationNames.TemporalHistoryTableSchema,
column.Table[SqlServerAnnotationNames.TemporalHistoryTableSchema]);

if (column[SqlServerAnnotationNames.TemporalPeriodStartColumnName] is string periodStartColumnName)
{
yield return new Annotation(
SqlServerAnnotationNames.TemporalPeriodStartColumnName,
periodStartColumnName);
}
yield return new Annotation(SqlServerAnnotationNames.TemporalIsPeriodStartColumn, true);
}

if (column[SqlServerAnnotationNames.TemporalPeriodEndColumnName] is string periodEndColumnName)
{
yield return new Annotation(
SqlServerAnnotationNames.TemporalPeriodEndColumnName,
periodEndColumnName);
}
if (column[SqlServerAnnotationNames.TemporalIsPeriodEndColumn] as bool? == true)
{
yield return new Annotation(SqlServerAnnotationNames.TemporalIsPeriodEndColumn, true);
}
}
}
Loading
Loading