private void RunMigrations(MigrationPlan migrationPlan) { if (NoWorkToDo(migrationPlan)) { Log.Info("No migrations to perform"); return; } Log.Info("Starting migrations"); Log.Info("Current version is " + migrationPlan.CurrentVersion); Log.Info("Target version is " + migrationPlan.TargetVersion); Log.Info(String.Format("Migrate action is: {0} from {1} to {2}", (migrationPlan.IsUp ? "UP" : "DOWN"), migrationPlan.CurrentVersion, migrationPlan.TargetVersion)); foreach (var step in migrationPlan.OrderedSteps) { var migrationInfo = step.MigrationInfo; try { RunMigration(step); } catch (NotSupportedByDialect nse) { HandleNotSupportedByDialectException(migrationInfo, nse); } catch (Exception ex) { var errorMsg = String.Format("Error running migration {0}: {1}", migrationInfo.Name, ex); Log.Error(errorMsg); _dataClient.RollBack(); var args = new MigrationErrorArgs(migrationInfo.Name, ex); FireOnMigrationError(args); if (!args.Handled) { throw new MigrationException(errorMsg, ex); } } } Log.Info("Done. Current version: " + migrationPlan.TargetVersion); }
private bool NoWorkToDo(MigrationPlan migrationPlan) { return migrationPlan.OrderedSteps.Count == 0; }
private void RunMigrations(MigrationPlan migrationPlan) { if (NoWorkToDo(migrationPlan)) { Log.Info("No migrations to perform"); return; } Log.Info("Starting migrations"); Log.Info("Current version is " + migrationPlan.CurrentVersion); Log.Info("Target version is " + migrationPlan.TargetVersion); Log.Info(String.Format("Migrate action is: {0} from {1} to {2}", (migrationPlan.IsUp ? "UP" : "DOWN"), migrationPlan.CurrentVersion, migrationPlan.TargetVersion)); foreach (var migrationInfo in migrationPlan.OrderedMigrationsToRun) { try { if (!migrationInfo.MigratesFor(_databaseKind)) { Log.Info(String.Format(" -> [{0}] {1} {2}() NOT PERFORMED for database {3}", migrationInfo.Version, migrationInfo.Name, migrationPlan.Direction, _databaseKind)); UpdateCurrentVersion(migrationInfo, migrationPlan.Direction); return; } Log.Info(String.Format(" -> [{0}] {1} {2}()", migrationInfo.Version, migrationInfo.Name, migrationPlan.Direction)); var migration = _migrationFactory.CreateMigration(migrationInfo.MigrationType); if (migrationPlan.IsUp) { migration.Up(); } else { migration.Down(); } UpdateCurrentVersion(migrationInfo, migrationPlan.Direction); } catch (NotSupportedByDialect nse) { HandleNotSupportedByDialectException(migrationInfo, nse); } catch (Exception ex) { string errorMsg = String.Format("Error running migration {0}: {1}", migrationInfo.Name, ex); Log.Error(errorMsg); _dataClient.RollBack(); throw new MigrationException(errorMsg, ex); } } Log.Info("Done. Current version: " + migrationPlan.TargetVersion); }
public void Run(long targetVersion) { List<MigrationInfo> migrationsFromAssembly = MigrationFinder.FindMigrations(_targetAssembly); VersionRepository.EnsureSchemaVersionTable(migrationsFromAssembly); List<long> migrationsFromDatabase = VersionRepository.GetAppliedMigrations(); var migrationPlan = new MigrationPlan(migrationsFromDatabase, migrationsFromAssembly, targetVersion); RunMigrations(migrationPlan); }
private bool NoWorkToDo(MigrationPlan migrationPlan) { return migrationPlan.OrderedMigrationsToRun.Count == 0; }