Пример #1
0
        public void CanBlockBreakingChangesByDefault()
        {
            InvalidOperationException ex = Assert.Throws <InvalidOperationException>(() =>
                                                                                     _runner.ApplyMigrationUp(
                                                                                         new MigrationInfo(7, TransactionBehavior.Default, true, new TestBreakingMigration()), true));

            Assert.NotNull(ex);

            Assert.AreEqual(
                "The migration 7: TestBreakingMigration is identified as a breaking change, and will not be executed unless the necessary flag (allow-breaking-changes|abc) is passed to the runner.",
                ex.Message);
        }
Пример #2
0
        public async Task UpAsync(bool clearFromVersionInfoTable)
        {
            if (!_project.IsDatabaseInitialized)
            {
                throw new InvalidOperationException("Cannot run migration: database connection has not been initialized");
            }

            await Task.Run(() =>
            {
                var context = _migrationsRepository.GetRunnerContext(_project.Profile, _project.Tags, false);
                using (var processor = _migrationsRepository.GetMigrationProcessor(_project.DatabaseType.Value, _project.ConnectionString, context))
                {
                    try
                    {
                        var runner = new MigrationRunner(_project.MigrationsAssembly, context, processor);

                        if (clearFromVersionInfoTable)
                        {
                            runner.VersionLoader.DeleteVersion(Version);
                        }

                        runner = new MigrationRunner(_project.MigrationsAssembly, context, processor);

                        var migrations = runner.MigrationLoader.LoadMigrations();
                        var info       = migrations.Single(m => m.Key == Version);

                        var sw = new Stopwatch();
                        sw.Start();

                        runner.ApplyMigrationUp(info.Value, IsUsingTransaction);

                        sw.Stop();

                        _log.Info("Successfully applied migration {0}: '{1}', took {2}", Version, Description, sw.Elapsed);
                    }
                    catch (Exception e)
                    {
                        throw new MigrationException("Could not apply migration", e, this);
                    }
                }
            });

            await InitializeAsync();
        }