Пример #1
0
        public async Task AddToVersionInfoTableAsync()
        {
            if (!_project.IsDatabaseInitialized)
            {
                throw new InvalidOperationException("Cannot add version to version info table: the 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);

                        runner.VersionLoader.UpdateVersionInfo(Version, Description);

                        _log.Info("Added version {0}: '{1}' to version info table", Version, Description);
                    }
                }
                catch (Exception e)
                {
                    throw new MigrationException("Could not add record to version info table", e, this);
                }
            });

            await InitializeAsync();
        }
Пример #2
0
        public Task RunAsync()
        {
            return(Task.Run(() =>
            {
                try
                {
                    var context = _migrationsRepository.GetRunnerContext(Name, Tags, false);
                    using (var processor = _migrationsRepository.GetMigrationProcessor(_project.DatabaseType.Value, _project.ConnectionString, context))
                    {
                        var runner = new MigrationRunner(_project.MigrationsAssembly, context, processor);

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

                        runner.ApplyProfiles();

                        sw.Stop();

                        _log.Info("Successfully ran profile '{0}', took {1}", Name, sw.Elapsed);
                    }
                }
                catch (Exception e)
                {
                    throw new ProfileException("Could not run profile", e, this);
                }
            }));
        }