public void CanUseCustomVersionInfoDefaultSchema() { ExecuteWithSupportedProcessors(processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), new RunnerContext(new TextWriterAnnouncer(System.Console.Out)) { Namespace = "FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass3" }, processor); IVersionTableMetaData tableMetaData = new TestVersionTableMetaData { SchemaName = null }; //ensure table doesn't exist if (processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName)) { runner.Down(new VersionMigration(tableMetaData)); } runner.Up(new VersionMigration(tableMetaData)); processor.TableExists(null, tableMetaData.TableName).ShouldBeTrue(); runner.Down(new VersionMigration(tableMetaData)); processor.TableExists(null, tableMetaData.TableName).ShouldBeFalse(); }); }
public void CanUseCustomVersionInfoDefaultSchema() { ExecuteWithSupportedProcessors( services => services .WithMigrationsIn("FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass3") .AddScoped <IVersionTableMetaDataAccessor>( _ => new PassThroughVersionTableMetaDataAccessor( new TestVersionTableMetaData() { SchemaName = null })), (serviceProvider, processor) => { var runner = serviceProvider.GetRequiredService <IMigrationRunner>(); IVersionTableMetaData tableMetaData = new TestVersionTableMetaData { SchemaName = null }; //ensure table doesn't exist if (processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName)) { runner.Down(new VersionMigration(tableMetaData)); } runner.MigrateUp(200909060930); processor.TableExists(null, tableMetaData.TableName).ShouldBeTrue(); runner.RollbackToVersion(0); processor.TableExists(null, tableMetaData.TableName).ShouldBeFalse(); }); }
public void VersionInfoCreationScriptsOnlyGeneratedOnceInPreviewMode() { if (!IntegrationTestOptions.SqlServer2008.IsEnabled) { return; } var connection = new SqlConnection(IntegrationTestOptions.SqlServer2008.ConnectionString); var processorOptions = new ProcessorOptions { PreviewOnly = true }; var outputSql = new StringWriter(); var announcer = new TextWriterAnnouncer(outputSql) { ShowSql = true }; var processor = new SqlServerProcessor(connection, new SqlServer2008Generator(), announcer, processorOptions, new SqlServerDbFactory()); try { var asm = typeof(MigrationRunnerTests).Assembly; var runnerContext = new RunnerContext(announcer) { Namespace = "FluentMigrator.Tests.Integration.Migrations", PreviewOnly = true }; var runner = new MigrationRunner(asm, runnerContext, processor); runner.MigrateUp(1, false); processor.CommitTransaction(); string schemaName = new TestVersionTableMetaData().SchemaName; var schemaAndTableName = string.Format("\\[{0}\\]\\.\\[{1}\\]", schemaName, TestVersionTableMetaData.TABLENAME); var outputSqlString = outputSql.ToString(); var createSchemaMatches = new Regex(string.Format("CREATE SCHEMA \\[{0}\\]", schemaName)).Matches(outputSqlString).Count; var createTableMatches = new Regex("CREATE TABLE " + schemaAndTableName).Matches(outputSqlString).Count; var createIndexMatches = new Regex("CREATE UNIQUE CLUSTERED INDEX \\[" + TestVersionTableMetaData.UNIQUEINDEXNAME + "\\] ON " + schemaAndTableName).Matches(outputSqlString).Count; var alterTableMatches = new Regex("ALTER TABLE " + schemaAndTableName).Matches(outputSqlString).Count; System.Console.WriteLine(outputSqlString); createSchemaMatches.ShouldBe(1); createTableMatches.ShouldBe(1); alterTableMatches.ShouldBe(1); createIndexMatches.ShouldBe(1); } finally { CleanupTestSqlServerDatabase(connection, processor); } }
public void CanUseCustomVersionInfo() { ExecuteWithSupportedProcessors( services => services .WithMigrationsIn("FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass3") .AddScoped <IVersionTableMetaDataAccessor>(_ => new PassThroughVersionTableMetaDataAccessor(new TestVersionTableMetaData())), (serviceProvider, processor) => { var runner = serviceProvider.GetRequiredService <IMigrationRunner>(); var tableMetaData = new TestVersionTableMetaData(); //ensure table doesn't exist if (processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName)) { runner.Down(new VersionMigration(tableMetaData)); } //ensure schema doesn't exist if (processor.SchemaExists(tableMetaData.SchemaName)) { runner.Down(new VersionSchemaMigration(tableMetaData)); } runner.MigrateUp(200909060930); processor.SchemaExists(tableMetaData.SchemaName).ShouldBeTrue(); processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName).ShouldBeTrue(); runner.RollbackToVersion(0); processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName).ShouldBeFalse(); processor.SchemaExists(tableMetaData.SchemaName).ShouldBeFalse(); }, true, #if NET461 typeof(SqlAnywhereProcessor), #endif typeof(SQLiteProcessor), typeof(MySqlProcessor), typeof(FirebirdProcessor)); }
public void CanUseCustomVersionInfo() { ExecuteWithSupportedProcessors(processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), new RunnerContext(new TextWriterAnnouncer(TestContext.Out)) { Namespace = "FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass3" }, processor); var tableMetaData = new TestVersionTableMetaData(); //ensure table doesn't exist if (processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName)) { runner.Down(new VersionMigration(tableMetaData)); } //ensure schema doesn't exist if (processor.SchemaExists(tableMetaData.SchemaName)) { runner.Down(new VersionSchemaMigration(tableMetaData)); } runner.Up(new VersionSchemaMigration(tableMetaData)); processor.SchemaExists(tableMetaData.SchemaName).ShouldBeTrue(); runner.Up(new VersionMigration(tableMetaData)); processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName).ShouldBeTrue(); runner.Down(new VersionMigration(tableMetaData)); processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName).ShouldBeFalse(); runner.Down(new VersionSchemaMigration(tableMetaData)); processor.SchemaExists(tableMetaData.SchemaName).ShouldBeFalse(); }, true, #if NET461 typeof(SqlAnywhereProcessor), #endif typeof(SQLiteProcessor), typeof(MySqlProcessor), typeof(FirebirdProcessor)); }