private static void RunMigration(MigrationInfo migrationInfo, DatabaseVersion currentVersion, IEnumerable <Script> initScripts, IEnumerable <Script> upScripts, IEnumerable <Script> downScripts, IEnumerable <Script> termScripts, IList <IStep> storedSteps, IScriptRunner scriptRunner, IDatabaseMetadataProvider databaseMetadataProvider, IVersionRespository versionRespository, IAppliedScriptsRepository appliedScriptsRepository) { var upDownSteps = upScripts.Select(u => new DatabaseStep(u, downScripts.FirstOrDefault(d => d.Version == u.Version))).ToList(); var initTermSteps = initScripts.Select(i => new DatabaseStep(i, termScripts.FirstOrDefault(t => t.Version == i.Version))).ToList(); if (migrationInfo.Direction == MigrationDirection.Down) { var downMigration = new DownMigration(databaseMetadataProvider, versionRespository, appliedScriptsRepository, migrationInfo.Forced); if (storedSteps.Any()) { Output.Warn("NOTE: Using stored applied scripts to perform downgrade instead of local 'down' scripts."); downMigration.Migrate(storedSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } else { downMigration.Migrate(upDownSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } if (!migrationInfo.TargetVersion.HasValue) { var termMigration = new TermMigration(databaseMetadataProvider, migrationInfo.Forced); termMigration.Migrate(initTermSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } else { Output.Info("A target version was provided, termination scripts will not be executed."); } } else { var initMigration = new InitMigration(databaseMetadataProvider, migrationInfo.Forced); initMigration.Migrate(initTermSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); EnsureVersioningTableIsInitialised(versionRespository, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); EnsureAppliedScriptsTableIsInitialised(appliedScriptsRepository, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); var upMigration = new UpMigration(versionRespository, appliedScriptsRepository, migrationInfo.Forced); upMigration.Migrate(upDownSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } }
private static void RunMigration(MigrationInfo migrationInfo, DatabaseVersion currentVersion, IEnumerable<Script> initScripts, IEnumerable<Script> upScripts, IEnumerable<Script> downScripts, IEnumerable<Script> termScripts, IList<IStep> storedSteps, IScriptRunner scriptRunner, IDatabaseMetadataProvider databaseMetadataProvider, IVersionRespository versionRespository, IAppliedScriptsRepository appliedScriptsRepository) { var upDownSteps = upScripts.Select(u => new DatabaseStep(u, downScripts.FirstOrDefault(d => d.Version == u.Version))).ToList(); var initTermSteps = initScripts.Select(i => new DatabaseStep(i, termScripts.FirstOrDefault(t => t.Version == i.Version))).ToList(); if (migrationInfo.Direction == MigrationDirection.Down) { var downMigration = new DownMigration(databaseMetadataProvider, versionRespository, appliedScriptsRepository, migrationInfo.Forced); if (storedSteps.Any()) { Output.Warn("NOTE: Using stored applied scripts to perform downgrade instead of local 'down' scripts."); downMigration.Migrate(storedSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } else { downMigration.Migrate(upDownSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } if (!migrationInfo.TargetVersion.HasValue) { var termMigration = new TermMigration(databaseMetadataProvider, migrationInfo.Forced); termMigration.Migrate(initTermSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } else { Output.Info("A target version was provided, termination scripts will not be executed."); } } else { var initMigration = new InitMigration(databaseMetadataProvider, migrationInfo.Forced); initMigration.Migrate(initTermSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); EnsureVersioningTableIsInitialised(versionRespository, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); EnsureAppliedScriptsTableIsInitialised(appliedScriptsRepository, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); var upMigration = new UpMigration(versionRespository, appliedScriptsRepository, migrationInfo.Forced); upMigration.Migrate(upDownSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } }
protected bool Equals(DatabaseVersion other) { return Version == other.Version && string.Equals(ScriptName, other.ScriptName); }
protected bool Equals(DatabaseVersion other) { return(Version == other.Version && string.Equals(ScriptName, other.ScriptName)); }