private static StoreMigration GenerateInitialMigration(DesignSchema schema, List <DesignLogRecord> log) { //if (schema.Changed) if (log.Any(r => r.Operation == DesignOperation.ExistingTableChanged)) { schema.VersionKey = Guid.NewGuid(); } var mp = new StoreMigration { Version = schema.Version, VersionKey = schema.VersionKey, Created = DateTime.UtcNow }; mp.Status = schema.Tables.Any() ? MigrationStatus.Editing : MigrationStatus.Empty; var cmd = new List <MigrationCommand>(); cmd.Add(new MigrationCommand { Operation = MigrationOperation.CreateSchema, SchemaName = schema.Name }); var tables = schema.Tables.OrderBy(t => t.Order); foreach (var t in tables) { var tm = new MigrationCommand { Operation = MigrationOperation.CreateTable, SchemaName = schema.Name, Table = DesignSchemaConvert.ToStoreDefinition(schema, t) }; tm.OperationCode = Enum.GetName(tm.Operation); cmd.Add(tm); } mp.Commands = cmd.ToArray(); return(mp); }
private static void GenerateRenameColumnOperation(DesignSchema schema, DesignLogRecord record, List <MigrationCommand> commands, List <DesignLogRecord> records) { var cid = record.ColumnId; var tid = record.TableId; var table = schema.Tables.FirstOrDefault(t => t.Id == tid); // table can be deleted after that if (table != null) { var column = table.Columns.FirstOrDefault(c => c.Id == cid); // column can be deleted after that //if (column != null) { var tm = new MigrationCommand { Operation = MigrationOperation.AlterColumnName, SchemaName = schema.Name, TableName = table.Name, ColumnName = record.OldValue, NewValue = record.NewValue }; tm.OperationCode = Enum.GetName(tm.Operation); commands.Add(tm); } } }
private static void ExtractColumnOperation(DesignSchema schema, DesignLogRecord record, List <MigrationCommand> commands, List <DesignLogRecord> records, MigrationOperation op) { var cid = record.ColumnId; var tid = record.TableId; // because this is a new column we can use it from schema var table = schema.Tables.FirstOrDefault(t => t.Id == tid); // table can be deleted after that if (table != null) { var column = table.Columns.FirstOrDefault(c => c.Id == cid); // column can be deleted after that if (column != null) { var tm = new MigrationCommand { Operation = op, SchemaName = schema.Name, TableName = table.Name, Column = DesignSchemaConvert.ToStoreProperty(schema, table, column) }; tm.OperationCode = Enum.GetName(tm.Operation); commands.Add(tm); } else { // if column created and deleted in this log time if (records.Any(r => r.ColumnId == cid && r.Operation == DesignOperation.AddColumn)) { // remove all log about this colunt var delLogs = records.Where(r => r.ColumnId == cid).ToList(); delLogs.ForEach(r => records.Remove(r)); return; } } } // if column created in this log time but not deleted if (!records.Any(r => r.ColumnId == cid && r.Operation == DesignOperation.DeleteColumn)) { if (records.Any(r => r.ColumnId == cid && r.Operation == DesignOperation.AddColumn)) { var delLogs = records.Where(r => r.ColumnId == cid).ToList(); delLogs.ForEach(r => records.Remove(r)); return; } } // Existed previously column - remove all logs except rename/delete var colLogs = records.Where(r => r.ColumnId == cid && r.Operation != DesignOperation.SetColumnName && r.Operation != DesignOperation.DeleteColumn).ToList(); colLogs.ForEach(r => records.Remove(r)); }
private MigratorOptions Init(MigrationCommand cmd) { TargetAssemblies = cmd.TargetAssemblies.ToList(); Namespace = cmd.Namespace; NestedNamespaces = cmd.NestedNamespaces; StartVersion = cmd.StartVersion; WorkingDirectory = cmd.WorkingDirectory; Tags = cmd.Tags.ToList(); return(this); }
public MigrationParameters(MigrationCommand command, int? versionOrStep, string mdlFileName, string platformAlias, string connectionString, string outputFileName) { this.Command = command; this.VersionOrStep = versionOrStep; this.MdlFileName = mdlFileName; this.PlatformAlias = platformAlias; this.ConnectionString = connectionString; this.OutputFileName = outputFileName; }
private MigratorOptions Init(MigrationCommand cmd) { TargetAssemblies = cmd.TargetAssemblies.ToList(); Namespace = cmd.Namespace; NestedNamespaces = cmd.NestedNamespaces; StartVersion = cmd.StartVersion; WorkingDirectory = cmd.WorkingDirectory; Tags = cmd.Tags?.ToList() ?? new List <string>(); AllowBreakingChanges = cmd.AllowBreakingChanges; return(this); }
private static void GenerateRenameSchemaOperation(DesignSchema schema, DesignLogRecord record, List <MigrationCommand> commands, List <DesignLogRecord> records) { var tm = new MigrationCommand { Operation = MigrationOperation.AlterSchemaName, SchemaName = record.OldValue, NewValue = record.NewValue }; tm.OperationCode = Enum.GetName(tm.Operation); commands.Add(tm); }
private static void GenerateDeleteTableOperation(DesignSchema schema, DesignLogRecord record, List <MigrationCommand> commands, List <DesignLogRecord> records) { var tm = new MigrationCommand { Operation = MigrationOperation.DeleteTable, SchemaName = schema.Name, TableName = record.TableName, }; tm.OperationCode = Enum.GetName(tm.Operation); commands.Add(tm); }
private MigratorOptions Init(MigrationCommand cmd) { TargetAssemblies = cmd.TargetAssemblies.ToList(); Namespace = cmd.Namespace; NestedNamespaces = cmd.NestedNamespaces; StartVersion = cmd.StartVersion; WorkingDirectory = cmd.WorkingDirectory; Tags = cmd.Tags?.ToList() ?? new List <string>(); AllowBreakingChanges = cmd.AllowBreakingChanges; SchemaName = cmd.SchemaName; IncludeUntaggedMigrations = !cmd.IncludeUntaggedMigrations.hasValue || (cmd.IncludeUntaggedMigrations.value ?? true); IncludeUntaggedMaintenances = cmd.IncludeUntaggedMaintenances; return(this); }
private static void GenerateDeleteColumnOperation(DesignSchema schema, DesignLogRecord record, List <MigrationCommand> commands, List <DesignLogRecord> records) { var tm = new MigrationCommand { Operation = MigrationOperation.DeleteColumn, SchemaName = schema.Name, TableName = record.TableName, ColumnName = record.ColumnName, Column = DesignSchemaConvert.ToStorePropertyMin(record.OldColumn), }; tm.OperationCode = Enum.GetName(tm.Operation); commands.Add(tm); }
private static void ExtractCreateTable(DesignSchema schema, DesignLogRecord record, List <MigrationCommand> commands, List <DesignLogRecord> records) { var id = record.TableId; // because this is a new table we can use it from schema var table = schema.Tables.FirstOrDefault(t => t.Id == id); // table can be created and then deleted if (table != null) { var tm = new MigrationCommand { Operation = MigrationOperation.CreateTable, SchemaName = schema.Name, Table = DesignSchemaConvert.ToStoreDefinition(schema, table) }; tm.OperationCode = Enum.GetName(tm.Operation); commands.Add(tm); } //else //{ // // table deleted - use original name // var first = records.First(r => r.TableId == id); // var originalName = first.OldValue ?? first.TableName; // var tm = new MigrationCommand // { // Operation = MigrationOperation.DeleteTable, // SchemaName = schema.Name, // TableName = originalName, // }; // tm.OperationCode = Enum.GetName(tm.Operation); // commands.Add(tm); //} // remove all logs about this table - only if table was not deleted var tableLogs = records.Where(r => r.TableId == id).ToList(); tableLogs.ForEach(r => records.Remove(r)); }
public Arguments(MigrationCommand command, string[] settings) { Command = command; Settings = settings; }
public MigrationCommandAttribute(MigrationCommand command) { this.command = command; }