Пример #1
0
        public async Task DownAsync()
        {
            if (!_project.IsDatabaseInitialized)
            {
                throw new InvalidOperationException("Cannot undo migration: database connection has not been initialized");
            }

            await Task.Run(() =>
            {
                try
                {
                    var context = _migrationsRepository.GetRunnerContext(_project.Profile, Tags, false);
                    using (var processor = _migrationsRepository.GetMigrationProcessor(_project.DatabaseType.Value, _project.ConnectionString, context))
                    {
                        var 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.ApplyMigrationDown(info.Value, true);

                        sw.Stop();

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