private void ScriptMigrations(MigratorBase migrator) { var scriptingMigrator = new MigratorScriptingDecorator(migrator); string start; string target; if (migrator.GetDatabaseMigrations().Any(s => IsMigration(s, TargetMigration))) { // Down migration, start is null, target is the target start = null; target = migrator.GetDatabaseMigrations().Single(s => IsMigration(s, TargetMigration)); } else { // Up migration, go from start to target. start = migrator.GetDatabaseMigrations().FirstOrDefault(); target = migrator.GetLocalMigrations().Single(s => IsMigration(s, TargetMigration)); } string startName = start ?? migrator.GetDatabaseMigrations().FirstOrDefault(); string scriptFileName = String.Format("{0}-{1}.sql", startName, target); if (File.Exists(scriptFileName)) { Log.Error("File already exists: {0}", scriptFileName); return; } // Generate script Log.Info("Scripting migration from {0} to {1}", startName, target); if (!WhatIf) { string script = scriptingMigrator.ScriptUpdate(start, target); // Write the script File.WriteAllText(scriptFileName, script); } Log.Info("Wrote script to {0}", scriptFileName); }
protected override void ExecuteCommandCore(MigratorBase migrator) { Log.Info("Migration Status for {0} on {1}", ConnectionString.InitialCatalog, ConnectionString.DataSource); foreach (var migration in migrator.GetDatabaseMigrations().Reverse()) { Log.Info("A {0}", migration); } foreach (var migration in migrator.GetPendingMigrations()) { Log.Info(" {0}", migration); } Log.Info("A = Applied"); }