public override void Execute(HortonOptions options) { if (!options.Unattend) { Program.PrintLine("=== Add Migration ==="); Program.PrintLine(); } var migrationName = ""; if (options.ExtraArguments.Length > 0) { migrationName = options.ExtraArguments[0]; } while (string.IsNullOrEmpty(migrationName)) { if (options.Unattend) { Program.PrintErrorLine("Migration name is required while running in Unattend mode. Specificy Migration name as the last argument."); Environment.Exit(1); } Program.PrintLine("Please enter a name for the migration and press return."); migrationName = Console.ReadLine(); Program.PrintLine(); } migrationName = migrationName.Replace(" ", "_"); var loader = new FileLoader(options.MigrationsDirectoryPath); loader.LoadAllFiles(); var lastMigrationScript = loader.Files.OfType<MigrationScript>().OrderBy(x => x.SerialNumber).Last(); var newSerialNumber = lastMigrationScript.SerialNumber + 1; var serialNumberDigits = lastMigrationScript.FileName.IndexOf('_'); var newMigrationDirectory = Path.GetDirectoryName(lastMigrationScript.FilePath); var migrationFileName = newSerialNumber.ToString().PadLeft(serialNumberDigits, '0') + "_" + migrationName + ".sql"; var newMigrationFullFilePath = Path.Combine(newMigrationDirectory, migrationFileName); Program.Print("Writing migration: "); Program.PrintLine(ConsoleColor.DarkGreen, newMigrationFullFilePath); File.WriteAllText(newMigrationFullFilePath, ""); if (!options.Unattend) { System.Diagnostics.Process.Start(newMigrationFullFilePath); Program.PrintLine(); Program.PrintLine("Finished."); } }
public override void Execute(HortonOptions options) { using (var schemaInfo = new SchemaInfo(options)) { schemaInfo.InitializeTable(); var loader = new FileLoader(options.MigrationsDirectoryPath); loader.LoadAllFiles(); Program.PrintLine("=== Info ==="); Program.PrintLine(); Program.PrintLine("The following scripts will execute..."); bool willExecuteMigrations = true; foreach (var file in loader.Files) { var existingRecord = schemaInfo.AppliedMigrations.SingleOrDefault(x => x.FileNameMD5Hash == file.FileNameHash); if (existingRecord != null) { if (file.ContentMatches(existingRecord.ContentSHA1Hash)) { continue; } if (file.ConflictOnContent) { Program.PrintLine(ConsoleColor.Red, $"\nCONFLICT: The script \"{file.FileName}\" has changed since it was applied on \"{existingRecord.AppliedUTC.ToString("yyyy-MM-dd HH:mm:ss.ff")}\"."); willExecuteMigrations = false; continue; } } Program.PrintLine(ConsoleColor.DarkGreen, $"\n\"{file.FileName}\" will execute on UPDATE."); } if (!willExecuteMigrations) { Program.PrintLine(ConsoleColor.Red, $"\nWARNING! Migrations will not execute until conflicts are resolved."); Environment.Exit(1); } Program.PrintLine(); Program.PrintLine("Finished."); } }
public override void Execute(HortonOptions options) { using (var schemaInfo = new SchemaInfo(options)) { schemaInfo.InitializeTable(); var loader = new FileLoader(options.MigrationsDirectoryPath); loader.LoadAllFiles(); Program.PrintLine("=== Sync ==="); Program.PrintLine(); Program.PrintLine("Synchronizing conflicting scripts..."); foreach (var file in loader.Files) { var existingRecord = schemaInfo.AppliedMigrations.SingleOrDefault(x => x.FileNameMD5Hash == file.FileNameHash); if (existingRecord != null) { if (!file.ContentMatches(existingRecord.ContentSHA1Hash)) { Program.Print(ConsoleColor.Red, $"\n\"{file.FileName}\" has changed since it was applied on \"{existingRecord.AppliedUTC.ToString("yyyy-MM-dd HH:mm:ss.ff")}\" and will be updated."); Program.Print(ConsoleColor.Red, " Type 'Y' to Continue."); Program.PrintLine(); var c = Console.ReadKey(); if (c.KeyChar == 'y' || c.KeyChar == 'Y') { Program.PrintLine($"\nUpdating \"{file.FileName}\" with hash \"{file.ContentSHA1Hash}\""); schemaInfo.ResyncMigration(file); } else { Program.PrintLine("\nAborting..."); Environment.Exit(1); } } } } Program.PrintLine(); Program.PrintLine("Finished."); } }