public static MigrationBuilder DisableTemporalTable( this MigrationBuilder migrationBuilder, string table, string schema = null) { DisableTemporalTableOperation operation = new DisableTemporalTableOperation() { Name = table, Schema = schema }; migrationBuilder.Operations.Add(operation); return(migrationBuilder); }
protected virtual void Generate(DisableTemporalTableOperation operation, IModel model, MigrationCommandListBuilder builder) { string _SchemaQualifiedTableName = Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema); builder .Append($"ALTER TABLE {_SchemaQualifiedTableName}") .Append(" SET (SYSTEM_VERSIONING = OFF)") .AppendLine() .EndCommand(); builder .Append($"ALTER TABLE {_SchemaQualifiedTableName}") .Append(" DROP PERIOD FOR SYSTEM_TIME") .AppendLine() .EndCommand(); }
protected virtual void Generate(DisableTemporalTableOperation operation, IndentedStringBuilder builder) { builder.AppendLine($".{nameof(MigrationBuilderExtensions.DisableTemporalTable)}("); using (builder.Indent()) { builder .Append("table: ") .Append(Code.Literal(operation.Name)); if (string.IsNullOrEmpty(operation.Schema) == false) { builder.AppendLine(","); builder .Append("schema: ") .Append(Code.Literal(operation.Schema)); } } builder.Append(")"); }
protected override IEnumerable <MigrationOperation> Diff(ITable source, ITable target, DiffContext diffContext) { var _SourceEntity = source.Model.Model.FindEntity(source.Name, source.Schema); var _TargetEntity = target.Model.Model.FindEntity(target.Name, target.Schema); var _SourceIsTemporal = _SourceEntity.HasTemporalTable(); var _TargetIsTemporal = _TargetEntity.HasTemporalTable(); List <MigrationOperation> _Operations = new List <MigrationOperation>(); _Operations.AddRange(base.Diff(source, target, diffContext).ToArray()); if (_SourceIsTemporal == false && _TargetIsTemporal == true) { EnableTemporalTableOperation enableTemporal = new EnableTemporalTableOperation() { Name = _TargetEntity.GetTableName(), Schema = _TargetEntity.GetSchema(), HistoryTable = _TargetEntity.GetHistoryTableName(), HistorySchema = _TargetEntity.GetHistoryTableSchema(), SysStartDate = _TargetEntity.GetStartDateColumnName(), SysEndDate = _TargetEntity.GetEndDateColumnName(), DataConsistencyCheck = _TargetEntity.DataConsistencyCheck() }; if (enableTemporal.HistorySchema != null) { //Ensure schema for history table. _Operations.AddRange(base.Add(enableTemporal.HistorySchema, diffContext)); } _Operations.Add(enableTemporal); } else if (_SourceIsTemporal == true && _TargetIsTemporal == false) { DisableTemporalTableOperation disableTemporal = new DisableTemporalTableOperation() { Name = _SourceEntity.GetTableName(), Schema = _SourceEntity.GetSchema() }; ////Don't drop the Start/End date column when we detect history tracking is disabled. //var _TemporalStartColumn = _SourceEntity.GetStartDateColumnName(); //var _TemporalEndColumn = _SourceEntity.GetEndDateColumnName(); //for (int i = 0; i < _Operations.Count; i++) //{ // if (_Operations[i] is DropColumnOperation dropColumnOperation) // { // if (dropColumnOperation.Table == _SourceEntity.GetTableName() && // (dropColumnOperation.Name == _TemporalStartColumn || dropColumnOperation.Name == _TemporalEndColumn)) // { // _Operations.RemoveAt(i); // i--; // } // } //} _Operations.Add(disableTemporal); } return(_Operations); }