public void CanUseCustomVersionInfo() { 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(); //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, typeof(SqliteProcessor)); }
public void CanUseVersionInfo() { ExecuteWithSupportedProcessors(processor => { var runner = new MigrationRunner(new MigrationConventions(), processor); //ensure table doesn't exist if (processor.TableExists(VersionInfo.TABLE_NAME)) runner.Down(new VersionMigration()); runner.Up(new VersionMigration()); processor.TableExists(VersionInfo.TABLE_NAME).ShouldBeTrue(); runner.Down(new VersionMigration()); processor.TableExists(VersionInfo.TABLE_NAME).ShouldBeFalse(); }); }
public void CanUseVersionInfo() { ExecuteWithSupportedProcessors(processor => { var runner = new MigrationRunner(new MigrationConventions(), processor); IVersionTableMetaData tableMetaData = new DefaultVersionTableMetaData(); //ensure table doesn't exist if (processor.TableExists(tableMetaData.TableName)) runner.Down(new VersionMigration(tableMetaData)); runner.Up(new VersionMigration(tableMetaData)); processor.TableExists(tableMetaData.TableName).ShouldBeTrue(); runner.Down(new VersionMigration(tableMetaData)); processor.TableExists(tableMetaData.TableName).ShouldBeFalse(); }); }
public void CanApplyForeignKeyConventionWithSchema() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestForeignKeyNamingConventionWithSchema()); processor.ConstraintExists("TestSchema", "Users", "FK_Users_GroupId_Groups_GroupId").ShouldBeTrue(); runner.Down(new TestForeignKeyNamingConvention()); }, false, typeof(SqliteProcessor)); }
public void CanRunMigration() { ExecuteWithSupportedProcessors(processor => { var conventions = new MigrationConventions(); var runner = new MigrationRunner(conventions, processor); runner.Up(new TestCreateAndDropTableMigration()); processor.TableExists("TestTable").ShouldBeTrue(); runner.Down(new TestCreateAndDropTableMigration()); processor.TableExists("TestTable").ShouldBeFalse(); }); }
public void CanApplyIndexConvention() { var connection = new SqlConnection(sqlServerConnectionString); connection.Open(); var processor = new SqlServerProcessor(connection, new SqlServerGenerator()); var conventions = new MigrationConventions(); var runner = new MigrationRunner(conventions, processor); runner.Up(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeTrue(); runner.Down(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeFalse(); }
public void CanAlterColumnWithSchema() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestCreateSchema()); runner.Up(new TestCreateAndDropTableMigrationWithSchema()); processor.ColumnExists("TestSchema", "TestTable2", "Name2").ShouldBeTrue(); processor.DefaultValueExists("TestSchema", "TestTable", "Name", "Anonymous").ShouldBeTrue(); runner.Up(new TestAlterColumnWithSchema()); processor.ColumnExists("TestSchema", "TestTable2", "Name2").ShouldBeTrue(); runner.Down(new TestAlterColumnWithSchema()); processor.ColumnExists("TestSchema", "TestTable2", "Name2").ShouldBeTrue(); runner.Down(new TestCreateAndDropTableMigrationWithSchema()); runner.Down(new TestCreateSchema()); }, true, new[] { typeof(SQLiteProcessor), typeof(FirebirdProcessor) }); }
public void CanApplyIndexConvention() { ExecuteWithSupportedProcessors( processor => { var conventions = new MigrationConventions(); var runner = new MigrationRunner(conventions, processor, new TextWriterAnnouncer(System.Console.Out), new StopWatch()); runner.Up(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeTrue(); runner.Down(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeFalse(); }); }
public void CreatesViewOnSqlServer() { ExecuteWithSqlServer(processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), new RunnerContext(new TextWriterAnnouncer(System.Console.Out)) { Namespace = "FluentMigrator.Tests.Integration.Migrations.SqlServerScriptMigration" }, processor); // First check that view does not exist try { processor.ReadTableData(string.Empty, "Foo"); // .. it does remove it runner.Down(new SqlServerScriptMigration()); } catch (SqlException ex){ // Not found .. proceed with test Assert.IsTrue(ex.Message.Contains("Invalid object name 'Foo'")); } runner.Up(new SqlServerScriptMigration()); processor.Exists("SELECT * FROM Foo").ShouldBeTrue(); runner.Down(new SqlServerScriptMigration()); }, IntegrationTestOptions.SqlServer, true); }
public void CanApplyIndexConvention() { ExecuteWithSupportedProcessors( processor => { var conventions = new MigrationConventions(); var runner = new MigrationRunner(conventions, processor); runner.Up(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeTrue(); runner.Down(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeFalse(); }); }
public void CanApplyIndexConvention() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeTrue(); runner.Down(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeFalse(); //processor.CommitTransaction(); }); }
public void CanApplyForeignKeyConvention() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestForeignKeyNamingConvention()); // This is a hack until MigrationVersionRunner and MigrationRunner are refactored and merged together //processor.CommitTransaction(); processor.ConstraintExists( "Users", "FK_Users_GroupId_Groups_GroupId" ).ShouldBeTrue(); runner.Down( new TestForeignKeyNamingConvention() ); }); }
public void CanApplyForeignKeyConvention() { var connection = new SqlConnection(sqlServerConnectionString); connection.Open(); var processor = new SqlServerProcessor(connection, new SqlServerGenerator()); var conventions = new MigrationConventions(); var runner = new MigrationRunner(conventions, processor); runner.Up(new TestForeignKeyNamingConvention()); processor.TableExists("Users").ShouldBeTrue(); processor.ConstraintExists( "Users", "FK_Users_GroupId_Groups_GroupId").ShouldBeTrue(); runner.Down(new TestForeignKeyNamingConvention()); processor.TableExists("Users").ShouldBeFalse(); }
public void CanSilentlyFail() { var processor = new Mock<IMigrationProcessor>(); processor.Setup(x => x.Process(It.IsAny<CreateForeignKeyExpression>())).Throws(new Exception("Error")); processor.Setup(x => x.Process(It.IsAny<DeleteForeignKeyExpression>())).Throws(new Exception("Error")); var conventions = new MigrationConventions(); var runner = new MigrationRunner(conventions, processor.Object) { SilentlyFail = true }; runner.Up(new TestForeignKeySilentFailure()); runner.CaughtExceptions.Count.ShouldBeGreaterThan(0); runner.Down(new TestForeignKeySilentFailure()); runner.CaughtExceptions.Count.ShouldBeGreaterThan(0); }
public void CanApplyForeignKeyConvention() { ExecuteWithSupportedProcessors( processor => { var conventions = new MigrationConventions(); var runner = new MigrationRunner(conventions, processor); runner.Up(new TestForeignKeyNamingConvention()); processor.TableExists("Users").ShouldBeTrue(); processor.ConstraintExists("Users", "FK_Users_GroupId_Groups_GroupId").ShouldBeTrue(); runner.Down(new TestForeignKeyNamingConvention()); processor.TableExists("Users").ShouldBeFalse(); }); }
public void CanRunMigration() { ExecuteWithSupportedProcessors(processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestCreateAndDropTableMigration()); processor.TableExists(null, "TestTable").ShouldBeTrue(); // This is a hack until MigrationVersionRunner and MigrationRunner are refactored and merged together //processor.CommitTransaction(); runner.Down(new TestCreateAndDropTableMigration()); processor.TableExists(null, "TestTable").ShouldBeFalse(); }); }
public void CanAlterTablesSchema() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestCreateSchema()); runner.Up(new TestCreateAndDropTableMigrationWithSchema()); processor.TableExists("TestSchema", "TestTable").ShouldBeTrue(); runner.Up(new TestAlterSchema()); processor.TableExists("NewSchema", "TestTable").ShouldBeTrue(); runner.Down(new TestAlterSchema()); processor.TableExists("TestSchema", "TestTable").ShouldBeTrue(); runner.Down(new TestCreateAndDropTableMigrationWithSchema()); runner.Down(new TestCreateSchema()); }, true, new[] { typeof(SqliteProcessor), typeof(FirebirdProcessor) }); }
public void CanSilentlyFail() { try { var processorOptions = new Mock<IMigrationProcessorOptions>(); processorOptions.SetupGet(x => x.PreviewOnly).Returns(false); var processor = new Mock<IMigrationProcessor>(); processor.Setup(x => x.Process(It.IsAny<CreateForeignKeyExpression>())).Throws(new Exception("Error")); processor.Setup(x => x.Process(It.IsAny<DeleteForeignKeyExpression>())).Throws(new Exception("Error")); processor.Setup(x => x.Options).Returns(processorOptions.Object); var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor.Object) { SilentlyFail = true }; runner.Up(new TestForeignKeySilentFailure()); runner.CaughtExceptions.Count.ShouldBeGreaterThan(0); runner.Down(new TestForeignKeySilentFailure()); runner.CaughtExceptions.Count.ShouldBeGreaterThan(0); } finally { ExecuteWithSupportedProcessors(processor => { MigrationRunner testRunner = SetupMigrationRunner(processor); testRunner.RollbackToVersion(0); }, false); } }
public void CanUpdateData() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestCreateSchema()); runner.Up(new TestCreateAndDropTableMigrationWithSchema()); runner.Up(new TestUpdateData()); DataSet upDs = processor.ReadTableData("TestSchema", "TestTable"); upDs.Tables[0].Rows.Count.ShouldBe(1); upDs.Tables[0].Rows[0][1].ShouldBe("Updated"); runner.Down(new TestUpdateData()); DataSet downDs = processor.ReadTableData("TestSchema", "TestTable"); downDs.Tables[0].Rows.Count.ShouldBe(1); downDs.Tables[0].Rows[0][1].ShouldBe("Test"); runner.Down(new TestCreateAndDropTableMigrationWithSchema()); runner.Down(new TestCreateSchema()); }, true, new[] { typeof(SqliteProcessor), typeof(FirebirdProcessor) }); }
public void CanRenameTableWithSchema() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestCreateSchema()); runner.Up(new TestCreateAndDropTableMigrationWithSchema()); processor.TableExists("TestSchema", "TestTable2").ShouldBeTrue(); runner.Up(new TestRenameTableMigrationWithSchema()); processor.TableExists("TestSchema", "TestTable2").ShouldBeFalse(); processor.TableExists("TestSchema", "TestTable'3").ShouldBeTrue(); runner.Down(new TestRenameTableMigrationWithSchema()); processor.TableExists("TestSchema", "TestTable'3").ShouldBeFalse(); processor.TableExists("TestSchema", "TestTable2").ShouldBeTrue(); runner.Down(new TestCreateAndDropTableMigrationWithSchema()); processor.TableExists("TestSchema", "TestTable2").ShouldBeFalse(); runner.Down(new TestCreateSchema()); //processor.CommitTransaction(); }); }
public void CanReverseCreateUniqueConstraintWithSchema() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestCreateSchema()); runner.Up(new TestCreateAndDropTableMigrationWithSchema()); runner.Up(new TestCreateUniqueConstraintWithSchemaWithReversing()); processor.ConstraintExists("TestSchema", "TestTable2", "TestUnique").ShouldBeTrue(); runner.Down(new TestCreateUniqueConstraintWithSchemaWithReversing()); processor.ConstraintExists("TestSchema", "TestTable2", "TestUnique").ShouldBeFalse(); runner.Down(new TestCreateAndDropTableMigrationWithSchema()); runner.Down(new TestCreateSchema()); }, true, new[] { typeof(SqliteProcessor) }); }
public void CanInsertData() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestCreateAndDropTableMigration()); DataSet ds = processor.ReadTableData(null, "TestTable"); ds.Tables[0].Rows.Count.ShouldBe(1); ds.Tables[0].Rows[0][1].ShouldBe("Test"); runner.Down(new TestCreateAndDropTableMigration()); }, true, new[] { typeof(SqliteProcessor) }); }
public void CanRenameColumnWithSchema() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestCreateSchema()); runner.Up(new TestCreateAndDropTableMigrationWithSchema()); processor.ColumnExists("TestSchema", "TestTable2", "Name").ShouldBeTrue(); runner.Up(new TestRenameColumnMigrationWithSchema()); processor.ColumnExists("TestSchema", "TestTable2", "Name").ShouldBeFalse(); processor.ColumnExists("TestSchema", "TestTable2", "Name'3").ShouldBeTrue(); runner.Down(new TestRenameColumnMigrationWithSchema()); processor.ColumnExists("TestSchema", "TestTable2", "Name'3").ShouldBeFalse(); processor.ColumnExists("TestSchema", "TestTable2", "Name").ShouldBeTrue(); runner.Down(new TestCreateAndDropTableMigrationWithSchema()); processor.ColumnExists("TestSchema", "TestTable2", "Name").ShouldBeFalse(); runner.Down(new TestCreateSchema()); }, true, typeof(SqliteProcessor), typeof(FirebirdProcessor)); }
public void CanCreateUniqueConstraint() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestCreateAndDropTableMigration()); processor.ConstraintExists(null, "TestTable2", "TestUnique").ShouldBeFalse(); runner.Up(new TestCreateUniqueConstraint()); processor.ConstraintExists(null, "TestTable2", "TestUnique").ShouldBeTrue(); runner.Down(new TestCreateUniqueConstraint()); processor.ConstraintExists(null, "TestTable2", "TestUnique").ShouldBeFalse(); runner.Down(new TestCreateAndDropTableMigration()); }, true, typeof(SqliteProcessor)); }
public void CanExecuteSql() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestExecuteSql()); runner.Down(new TestExecuteSql()); }, true, new[] { typeof(FirebirdProcessor) }); }
public void CanCreateSequenceWithSchema() { Action<IMigrationProcessor> action = processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestCreateSequence()); processor.SequenceExists("TestSchema", "TestSequence"); runner.Down(new TestCreateSequence()); processor.SequenceExists("TestSchema", "TestSequence").ShouldBeFalse(); }; ExecuteWithSqlServer2012( action,true); ExecuteWithPostgres(action, IntegrationTestOptions.Postgres, true); }
public void CanCreateSequence() { ExecuteWithSqlServer2012( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestCreateSequence()); processor.SequenceExists(null, "TestSequence"); runner.Down(new TestCreateSequence()); processor.SequenceExists(null, "TestSequence").ShouldBeFalse(); }, true); }
public void CanCreateAndDropIndexWithSchema() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestCreateSchema()); runner.Up(new TestCreateAndDropTableMigrationWithSchema()); processor.IndexExists("TestSchema", "TestTable", "IX_TestTable_Name").ShouldBeFalse(); runner.Up(new TestCreateAndDropIndexMigrationWithSchema()); processor.IndexExists("TestSchema", "TestTable", "IX_TestTable_Name").ShouldBeTrue(); runner.Down(new TestCreateAndDropIndexMigrationWithSchema()); processor.IndexExists("TestSchema", "TestTable", "IX_TestTable_Name").ShouldBeFalse(); runner.Down(new TestCreateAndDropTableMigrationWithSchema()); processor.IndexExists("TestSchema", "TestTable", "IX_TestTable_Name").ShouldBeFalse(); runner.Down(new TestCreateSchema()); //processor.CommitTransaction(); }, false, new[] { typeof(SqliteProcessor), typeof(FirebirdProcessor) }); }
public void CanCreateAndDropIndex() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestCreateAndDropTableMigration()); processor.IndexExists(null, "TestTable", "IX_TestTable_Name").ShouldBeFalse(); runner.Up(new TestCreateAndDropIndexMigration()); processor.IndexExists(null, "TestTable", "IX_TestTable_Name").ShouldBeTrue(); runner.Down(new TestCreateAndDropIndexMigration()); processor.IndexExists(null, "TestTable", "IX_TestTable_Name").ShouldBeFalse(); runner.Down(new TestCreateAndDropTableMigration()); processor.IndexExists(null, "TestTable", "IX_TestTable_Name").ShouldBeFalse(); //processor.CommitTransaction(); }); }
public void CanApplyIndexConventionWithSchema() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestIndexNamingConventionWithSchema()); processor.IndexExists("TestSchema", "Users", "IX_Users_GroupId").ShouldBeTrue(); processor.TableExists("TestSchema", "Users").ShouldBeTrue(); runner.Down(new TestIndexNamingConventionWithSchema()); processor.IndexExists("TestSchema", "Users", "IX_Users_GroupId").ShouldBeFalse(); processor.TableExists("TestSchema", "Users").ShouldBeFalse(); }); }