Skip to content
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 @@ -3322,7 +3322,7 @@ private IReadOnlyList<MigrationOperation> RewriteOperations(

// we removed the table, so we no longer need it's temporal information
// there will be no more operations involving this table
temporalTableInformationMap.Remove((tableName, schema));
temporalTableInformationMap.Remove((tableName, rawSchema));

break;
}
Expand All @@ -3346,7 +3346,7 @@ private IReadOnlyList<MigrationOperation> RewriteOperations(

// since table was renamed, update entry in the temporal info map
temporalTableInformationMap[(renameTableOperation.NewName!, renameTableOperation.NewSchema)] = temporalInformation;
temporalTableInformationMap.Remove((tableName, schema));
temporalTableInformationMap.Remove((tableName, rawSchema));

break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,75 @@ public virtual void MoveTableOperation_legacy()
""");
}

[Fact] // Issue #38601
public virtual void RenameTableOperation_temporal_table_moved_into_model_default_schema()
{
Generate(
modelBuilder =>
{
modelBuilder.HasDefaultSchema("dbo");
modelBuilder.Entity(
"Customer", e =>
{
e.Property<int>("Id").ValueGeneratedOnAdd();
e.Property<string>("Name");
e.Property<DateTime>("PeriodStart").ValueGeneratedOnAddOrUpdate();
e.Property<DateTime>("PeriodEnd").ValueGeneratedOnAddOrUpdate();
e.HasKey("Id");
e.ToTable(
"Customers", tb => tb.IsTemporal(ttb =>
{
ttb.UseHistoryTable("CustomersHistory");
ttb.HasPeriodStart("PeriodStart");
ttb.HasPeriodEnd("PeriodEnd");
}));
});
},
new EnsureSchemaOperation { Name = "dbo" },
new RenameTableOperation
{
Name = "Customers",
Schema = null,
NewName = "Customers",
NewSchema = "dbo",
[SqlServerAnnotationNames.IsTemporal] = true,
[SqlServerAnnotationNames.TemporalHistoryTableName] = "CustomersHistory",
[SqlServerAnnotationNames.TemporalHistoryTableSchema] = null,
[SqlServerAnnotationNames.TemporalPeriodStartColumnName] = "PeriodStart",
[SqlServerAnnotationNames.TemporalPeriodEndColumnName] = "PeriodEnd"
},
new AlterTableOperation
{
Name = "Customers",
Schema = "dbo",
[SqlServerAnnotationNames.IsTemporal] = true,
[SqlServerAnnotationNames.TemporalHistoryTableName] = "CustomersHistory",
[SqlServerAnnotationNames.TemporalHistoryTableSchema] = "dbo",
[SqlServerAnnotationNames.TemporalPeriodStartColumnName] = "PeriodStart",
[SqlServerAnnotationNames.TemporalPeriodEndColumnName] = "PeriodEnd",
OldTable =
{
[SqlServerAnnotationNames.IsTemporal] = true,
[SqlServerAnnotationNames.TemporalHistoryTableName] = "CustomersHistory",
[SqlServerAnnotationNames.TemporalHistoryTableSchema] = null,
[SqlServerAnnotationNames.TemporalPeriodStartColumnName] = "PeriodStart",
[SqlServerAnnotationNames.TemporalPeriodEndColumnName] = "PeriodEnd"
}
});

AssertSql(
"""
ALTER TABLE [dbo].[Customers] SET (SYSTEM_VERSIONING = OFF)

GO

ALTER SCHEMA [dbo] TRANSFER [Customers];
GO

ALTER TABLE [dbo].[Customers] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [dbo].[CustomersHistory]))
""");
}

[Fact]
public virtual void RenameIndexOperations_throws_when_no_table()
{
Expand Down
Loading