public virtual void ApplyMigrationUp(IMigrationInfo migrationInfo, bool useTransaction) { if (migrationInfo == null) { throw new ArgumentNullException("migrationInfo"); } if (!_alreadyOutputPreviewOnlyModeWarning && Processor.Options.PreviewOnly) { _announcer.Heading("PREVIEW-ONLY MODE"); _alreadyOutputPreviewOnlyModeWarning = true; } if (!migrationInfo.IsAttributed() || !VersionLoader.VersionInfo.HasAppliedMigration(migrationInfo.Version)) { var name = migrationInfo.GetName(); _announcer.Heading(string.Format("{0} migrating", name)); _stopWatch.Start(); using (IMigrationScope scope = _migrationScopeHandler.CreateOrWrapMigrationScope(useTransaction)) { try { if (migrationInfo.IsAttributed() && migrationInfo.IsBreakingChange && !RunnerContext.PreviewOnly && !RunnerContext.AllowBreakingChange) { throw new InvalidOperationException( string.Format( "The migration {0} is identified as a breaking change, and will not be executed unless the necessary flag (allow-breaking-changes|abc) is passed to the runner.", migrationInfo.GetName())); } ExecuteMigration(migrationInfo.Migration, (m, c) => m.GetUpExpressions(c)); if (migrationInfo.IsAttributed()) { VersionLoader.UpdateVersionInfo(migrationInfo.Version, migrationInfo.Description ?? migrationInfo.Migration.GetType().Name); } scope.Complete(); } catch { if (useTransaction && scope.IsActive) { scope.Cancel(); // SQLAnywhere needs explicit call to rollback transaction } throw; } _stopWatch.Stop(); _announcer.Say(string.Format("{0} migrated", name)); _announcer.ElapsedTime(_stopWatch.ElapsedTime()); } } }
private void ApplyMigrationUp(long version) { if (!_alreadyOutputPreviewOnlyModeWarning && Processor.Options.PreviewOnly) { _announcer.Heading("PREVIEW-ONLY MODE"); _alreadyOutputPreviewOnlyModeWarning = true; } if (!VersionLoader.VersionInfo.HasAppliedMigration(version)) { Up(MigrationLoader.Migrations[version]); VersionLoader.UpdateVersionInfo(version); } }
public virtual void ApplyMigrationUp(IMigrationInfo migrationInfo, bool useTransaction) { if (migrationInfo == null) { throw new ArgumentNullException("migrationInfo"); } if (!_alreadyOutputPreviewOnlyModeWarning && Processor.Options.PreviewOnly) { _announcer.Heading("PREVIEW-ONLY MODE"); _alreadyOutputPreviewOnlyModeWarning = true; } if (!migrationInfo.IsAttributed() || !VersionLoader.VersionInfo.HasAppliedMigration(migrationInfo.Version)) { var name = migrationInfo.GetName(); _announcer.Heading(string.Format("{0} migrating", name)); _stopWatch.Start(); using (IMigrationScope scope = _migrationScopeHandler.CreateOrWrapMigrationScope(useTransaction)) { try { ExecuteMigration(migrationInfo.Migration, (m, c) => m.GetUpExpressions(c)); if (migrationInfo.IsAttributed()) { VersionLoader.UpdateVersionInfo(migrationInfo.Version, migrationInfo.Description ?? migrationInfo.Migration.GetType().Name); } scope.Complete(); } catch { if (useTransaction && scope.IsActive) { scope.Cancel(); // SQLAnywhere needs explicit call to rollback transaction } throw; } _stopWatch.Stop(); _announcer.Say(string.Format("{0} migrated", name)); _announcer.ElapsedTime(_stopWatch.ElapsedTime()); } } }
public void MigrateToLatest(string connectionString, MigrationType migrationType) { _announcer.Heading("Migrating " + connectionString); var assembly = Assembly.GetExecutingAssembly(); var migrationContext = new RunnerContext(_announcer) { Namespace = "NzbDrone.Core.Datastore.Migration", ApplicationContext = new MigrationContext { MigrationType = migrationType, SQLiteAlter = _sqLiteAlter, MigrationHelper = _migrationHelper, } }; var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; var factory = new SqliteProcessorFactory(); var processor = factory.Create(connectionString, _announcer, options); var runner = new MigrationRunner(assembly, migrationContext, processor); runner.MigrateUp(true); }
public void MigrateToLatest(string connectionString, MigrationType migrationType, Action <NzbDroneMigrationBase> beforeMigration) { var sw = Stopwatch.StartNew(); _announcer.Heading("Migrating " + connectionString); var assembly = Assembly.GetExecutingAssembly(); var migrationContext = new RunnerContext(_announcer) { Namespace = "NzbDrone.Core.Datastore.Migration", ApplicationContext = new MigrationContext(migrationType, beforeMigration) }; var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; var factory = new NzbDroneSqliteProcessorFactory(); var processor = factory.Create(connectionString, _announcer, options); var runner = new MigrationRunner(assembly, migrationContext, processor); runner.MigrateUp(true); sw.Stop(); _announcer.ElapsedTime(sw.Elapsed); }
public void Migrate(string connectionString, MigrationContext migrationContext) { var sw = Stopwatch.StartNew(); _announcer.Heading("Migrating " + connectionString); var assembly = Assembly.GetExecutingAssembly(); var runnerContext = new RunnerContext(_announcer) { Namespace = "NzbDrone.Core.Datastore.Migration", ApplicationContext = migrationContext }; var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; var factory = new NzbDroneSqliteProcessorFactory(); var processor = factory.Create(connectionString, _announcer, options); var runner = new MigrationRunner(assembly, runnerContext, processor); if (migrationContext.DesiredVersion.HasValue) { runner.MigrateUp(migrationContext.DesiredVersion.Value, true); } else { runner.MigrateUp(true); } sw.Stop(); _announcer.ElapsedTime(sw.Elapsed); }
private void ApplyMigrationUp(IMigrationInfo migrationInfo, bool useTransaction) { if (!_alreadyOutputPreviewOnlyModeWarning && Processor.Options.PreviewOnly) { _announcer.Heading("PREVIEW-ONLY MODE"); _alreadyOutputPreviewOnlyModeWarning = true; } if (!VersionLoader.VersionInfo.HasAppliedMigration(migrationInfo.Version)) { var name = GetMigrationName(migrationInfo); _announcer.Heading(string.Format("{0} migrating", name)); try { _stopWatch.Start(); if (useTransaction) { Processor.BeginTransaction(); } ExecuteMigration(migrationInfo.Migration, (m, c) => m.GetUpExpressions(c)); VersionLoader.UpdateVersionInfo(migrationInfo.Version); if (useTransaction) { Processor.CommitTransaction(); } _stopWatch.Stop(); _announcer.Say(string.Format("{0} migrated", name)); _announcer.ElapsedTime(_stopWatch.ElapsedTime()); } catch (Exception) { if (useTransaction) { Processor.RollbackTransaction(); } throw; } } }
public static void Heading(this IAnnouncer announcer, string message, params object[] args) { announcer.Heading(string.Format(message, args)); }
public void Heading_Should_Heading_string_formatted_message() { Mock.Get(announcer).Setup(a => a.Heading("Hello Heading")); announcer.Heading("Hello {0}", "Heading"); }
/// <inheritdoc /> protected override void WriteHeading(string message) { _announcer.Heading(message); }
public void HeadingShouldHeadingStringFormattedMessage() { Mock.Get(_announcer).Setup(a => a.Heading("Hello Heading")); _announcer.Heading("Hello {0}", "Heading"); }