示例#1
0
        private void RunMigrations(MigrationPlan migrationPlan)
        {
            if (NoWorkToDo(migrationPlan))
            {
                Log("No migrations to perform");
                return;
            }
            Log("Starting migrations");
            Log("Current version is " + migrationPlan.CurrentVersion);
            Log("Target version is " + migrationPlan.TargetVersion);
            Log(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 (NotSupportedByDialectException nse) {
                    HandleNotSupportedByDialectException(migrationInfo, nse);
                }
                catch (Exception ex) {
                    var errorMsg = String.Format("Error running migration {0}: {1}", migrationInfo.Name, ex);
                    LogError(errorMsg);
                    _dataClient.RollBack();
                    var args = new MigrationErrorArgs(migrationInfo.Name, ex);
                    FireOnMigrationError(args);
                    if (!args.Handled)
                    {
                        throw new MigrationException(errorMsg, ex);
                    }
                }
            }
            Log("Done. Current version: " + migrationPlan.TargetVersion);
        }
示例#2
0
 private bool NoWorkToDo(MigrationPlan migrationPlan)
 {
     return(migrationPlan.OrderedSteps.Count == 0);
 }