예제 #1
0
        public void when_there_are_no_migration_scripts_then_none_are_ever_executed()
        {
            var migration = new InitMigration(_mockMetadataProvider.Object, false);

            migration.Migrate(Enumerable.Empty <IStep>(), null, null, _mockScriptRunner.Object, Some.String(), Some.String());

            _mockScriptRunner.Verify(m => m.Execute(It.IsAny <IScript>()), Times.Never);
        }
예제 #2
0
        public void for_each_migration_script_upgraded_no_versioning_is_necessary()
        {
            var migration = new InitMigration(_mockMetadataProvider.Object, false);

            migration.Migrate(SomeScripts, null, null, _mockScriptRunner.Object, Some.String(), Some.String());

            _mockVersionRepository.Verify(m => m.InsertVersion(SomeScripts[0].ForwardScript.AsDatabaseVersion(), It.IsAny <string>()), Times.Never);
            _mockVersionRepository.Verify(m => m.InsertVersion(SomeScripts[1].ForwardScript.AsDatabaseVersion(), It.IsAny <string>()), Times.Never);
        }
예제 #3
0
        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);
            }
        }