static void Main() { // Create migration announcer. var announcer = new TextWriterAnnouncer(Console.WriteLine) { ShowSql = true }; // Create migration context. var migrationContext = new RunnerContext(announcer); // Create migration options, factory and runner. var options = new ProcessorOptions { PreviewOnly = false, Timeout = 60 }; var factory = new SqliteProcessorFactory(); var processor = factory.Create(ConnectionString, announcer, options); var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), migrationContext, processor); // Update database. runner.MigrateUp(long.MaxValue, true); // Rollback database. runner.MigrateDown(long.MinValue, true); }
public void CanMigrateASpecificVersionDown() { try { ExecuteWithSupportedProcessors(processor => { MigrationRunner runner = SetupMigrationRunner(processor); runner.MigrateUp(1); runner.VersionLoader.VersionInfo.HasAppliedMigration(1).ShouldBeTrue(); processor.TableExists(null, "Users").ShouldBeTrue(); }, false, typeof(SqliteProcessor)); ExecuteWithSupportedProcessors(processor => { MigrationRunner testRunner = SetupMigrationRunner(processor); testRunner.MigrateDown(0); testRunner.VersionLoader.VersionInfo.HasAppliedMigration(1).ShouldBeFalse(); processor.TableExists(null, "Users").ShouldBeFalse(); }, false, typeof(SqliteProcessor)); } finally { ExecuteWithSupportedProcessors(processor => { MigrationRunner testRunner = SetupMigrationRunner(processor); testRunner.RollbackToVersion(0); }, false); } }
private void RollbackDatabase() { var version = Convert.ToInt64(Parameters.RollbackToVersion, CultureInfo.CurrentCulture); MigrationRunner runner = (MigrationRunner)this.serviceProvider.GetRequiredService <IMigrationRunner>(); // Validate the version number that has been passed in if (!runner.VersionLoader.VersionInfo.HasAppliedMigration(Convert.ToInt64(Parameters.RollbackToVersion, CultureInfo.CurrentCulture))) { Console.WriteLine(string.Empty); Console.WriteLine($"Version {Parameters.RollbackToVersion} does not exist. Exiting...", Color.Red); Console.WriteLine(string.Empty); return; } runner.MigrateDown(version); }
public void Migrate(string connectionString, Assembly assembly) { var announcer = new TextWriterAnnouncer(s => _log.LogInformation(s)); var migrationContext = new RunnerContext(announcer); var options = new MigrationOptions { PreviewOnly = false, Timeout = 60, ProviderSwitches = string.Empty }; var factory = new SqlServerProcessorFactory(); using (var processor = factory.Create(connectionString, announcer, options)) { var runner = new MigrationRunner(assembly, migrationContext, processor); runner.MigrateDown(0); runner.MigrateUp(true); } }
public void MigrateDown(long targetVersion) { var announcer = new TextWriterAnnouncer(s => Debug.WriteLine(s)); var assembly = Assembly.GetExecutingAssembly(); var migrationContext = new RunnerContext(announcer); var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2012ProcessorFactory(); using (var processor = factory.Create(connectionString, announcer, options)) { var runner = new MigrationRunner(assembly, migrationContext, processor); runner.MigrateDown(targetVersion, true); } }
public static void Down(string connectionString) { var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s)); var assembly = Assembly.GetExecutingAssembly(); var migrationContext = new RunnerContext(announcer); var options = new MigrationOptions { PreviewOnly = false, Timeout = 60, ProviderSwitches = string.Empty }; var factory = new PostgresProcessorFactory(); using (var processor = factory.Create(connectionString, announcer, options)) { var runner = new MigrationRunner(assembly, migrationContext, processor); runner.MigrateDown(0); } }
public static void MigrateDown(string connectionString) { var announcer = new NullAnnouncer(); var assembly = Assembly.GetExecutingAssembly(); var migrationContext = new RunnerContext(announcer) { Namespace = "Hinata.Data.Migrations" }; var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2012ProcessorFactory(); var processor = factory.Create(connectionString, announcer, options); var runner = new MigrationRunner(assembly, migrationContext, processor); runner.MigrateDown(-1); }
public static void MigrateDown(long toVersion, string MigrationNamespace, string connectionString) { var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s)); var assembly = Assembly.GetExecutingAssembly(); var migrationContext = new RunnerContext(announcer) { Namespace = MigrationNamespace }; var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; var factory = new FluentMigrator.Runner.Processors.Postgres.PostgresProcessorFactory(); using (var processor = factory.Create(connectionString, announcer, options)) { var runner = new MigrationRunner(assembly, migrationContext, processor); runner.MigrateDown(toVersion); } }
public void ProfilesAreAppliedWhenMigrateDownIsCalled() { _runner.MigrateDown(2009010101); _profileLoaderMock.Verify(x => x.ApplyProfiles(), Times.Once()); }
public void DropSchema() { runner.MigrateDown(0); }