Search in sources :

Example 1 with MockSqlGeneratorChain

use of liquibase.sqlgenerator.MockSqlGeneratorChain in project liquibase by liquibase.

the class DropColumnGeneratorTest method testDropMultipleColumnsMySQL.

@Test
public void testDropMultipleColumnsMySQL() {
    DropColumnStatement drop = new DropColumnStatement(Arrays.asList(new DropColumnStatement(null, null, "TEST_TABLE", "col1"), new DropColumnStatement(null, null, "TEST_TABLE", "col2")));
    Assert.assertFalse(generatorUnderTest.validate(drop, new MySQLDatabase(), new MockSqlGeneratorChain()).hasErrors());
    Sql[] sql = generatorUnderTest.generateSql(drop, new MySQLDatabase(), new MockSqlGeneratorChain());
    Assert.assertEquals(1, sql.length);
    Assert.assertEquals("ALTER TABLE TEST_TABLE DROP col1, DROP col2", sql[0].toSql());
    Assert.assertEquals("[DEFAULT, TEST_TABLE, TEST_TABLE.col1, TEST_TABLE.col2]", String.valueOf(sql[0].getAffectedDatabaseObjects()));
}
Also used : MySQLDatabase(liquibase.database.core.MySQLDatabase) DropColumnStatement(liquibase.statement.core.DropColumnStatement) MockSqlGeneratorChain(liquibase.sqlgenerator.MockSqlGeneratorChain) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 2 with MockSqlGeneratorChain

use of liquibase.sqlgenerator.MockSqlGeneratorChain in project liquibase by liquibase.

the class AddColumnGeneratorTest method testAddColumnAfter.

@Test
public void testAddColumnAfter() {
    AddColumnStatement statement = new AddColumnStatement(null, null, TABLE_NAME, COLUMN_NAME, COLUMN_TYPE, null);
    statement.setAddAfterColumn("column_after");
    assertFalse(generatorUnderTest.validate(statement, new MySQLDatabase(), new MockSqlGeneratorChain()).hasErrors());
}
Also used : MySQLDatabase(liquibase.database.core.MySQLDatabase) AddColumnStatement(liquibase.statement.core.AddColumnStatement) MockSqlGeneratorChain(liquibase.sqlgenerator.MockSqlGeneratorChain) Test(org.junit.Test) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest)

Example 3 with MockSqlGeneratorChain

use of liquibase.sqlgenerator.MockSqlGeneratorChain in project liquibase by liquibase.

the class AddColumnGeneratorTest method testAddMultipleColumnsMySql.

@Test
public void testAddMultipleColumnsMySql() {
    AddColumnStatement columns = new AddColumnStatement(new AddColumnStatement(null, null, TABLE_NAME, "column1", "INT", null, new NotNullConstraint()), new AddColumnStatement(null, null, TABLE_NAME, "column2", "INT", null, new NotNullConstraint()));
    assertFalse(generatorUnderTest.validate(columns, new MySQLDatabase(), new MockSqlGeneratorChain()).hasErrors());
    Sql[] sql = generatorUnderTest.generateSql(columns, new MySQLDatabase(), new MockSqlGeneratorChain());
    assertEquals(1, sql.length);
    assertEquals("ALTER TABLE " + TABLE_NAME + " ADD column1 INT NOT NULL, ADD column2 INT NOT NULL", sql[0].toSql());
    assertEquals("[DEFAULT, table_name, table_name.column1, table_name.column2]", String.valueOf(sql[0].getAffectedDatabaseObjects()));
}
Also used : MySQLDatabase(liquibase.database.core.MySQLDatabase) AddColumnStatement(liquibase.statement.core.AddColumnStatement) NotNullConstraint(liquibase.statement.NotNullConstraint) MockSqlGeneratorChain(liquibase.sqlgenerator.MockSqlGeneratorChain) Sql(liquibase.sql.Sql) Test(org.junit.Test) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest)

Example 4 with MockSqlGeneratorChain

use of liquibase.sqlgenerator.MockSqlGeneratorChain in project liquibase by liquibase.

the class MarkChangeSetRanGeneratorTest method generateSql_markRan.

@Test
public void generateSql_markRan() {
    Sql[] sqls = new MarkChangeSetRanGenerator().generateSql(new MarkChangeSetRanStatement(new ChangeSet("1", "a", false, false, "c", null, null, null), ChangeSet.ExecType.MARK_RAN), new MockDatabase(), new MockSqlGeneratorChain());
    assertEquals(1, sqls.length);
    assertTrue(sqls[0].toSql(), sqls[0].toSql().contains("MARK_RAN"));
}
Also used : MarkChangeSetRanStatement(liquibase.statement.core.MarkChangeSetRanStatement) MockDatabase(liquibase.sdk.database.MockDatabase) ChangeSet(liquibase.changelog.ChangeSet) MockSqlGeneratorChain(liquibase.sqlgenerator.MockSqlGeneratorChain) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 5 with MockSqlGeneratorChain

use of liquibase.sqlgenerator.MockSqlGeneratorChain in project liquibase by liquibase.

the class AddColumnGeneratorDefaultClauseBeforeNotNullTest method validate_noAutoIncrementWithDerby.

@Test
public void validate_noAutoIncrementWithDerby() {
    ValidationErrors validationErrors = generatorUnderTest.validate(new AddColumnStatement(null, null, "table_name", "column_name", "int", null, new AutoIncrementConstraint("column_name")), new DerbyDatabase(), new MockSqlGeneratorChain());
    assertTrue(validationErrors.getErrorMessages().contains("Cannot add an identity column to derby"));
}
Also used : AutoIncrementConstraint(liquibase.statement.AutoIncrementConstraint) ValidationErrors(liquibase.exception.ValidationErrors) AddColumnStatement(liquibase.statement.core.AddColumnStatement) MockSqlGeneratorChain(liquibase.sqlgenerator.MockSqlGeneratorChain) Test(org.junit.Test)

Aggregations

MockSqlGeneratorChain (liquibase.sqlgenerator.MockSqlGeneratorChain)6 Test (org.junit.Test)5 MySQLDatabase (liquibase.database.core.MySQLDatabase)4 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)4 AddColumnStatement (liquibase.statement.core.AddColumnStatement)4 Sql (liquibase.sql.Sql)3 AutoIncrementConstraint (liquibase.statement.AutoIncrementConstraint)2 ChangeSet (liquibase.changelog.ChangeSet)1 DB2Database (liquibase.database.core.DB2Database)1 DerbyDatabase (liquibase.database.core.DerbyDatabase)1 H2Database (liquibase.database.core.H2Database)1 OracleDatabase (liquibase.database.core.OracleDatabase)1 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)1 ValidationErrors (liquibase.exception.ValidationErrors)1 MockDatabase (liquibase.sdk.database.MockDatabase)1 NotNullConstraint (liquibase.statement.NotNullConstraint)1 PrimaryKeyConstraint (liquibase.statement.PrimaryKeyConstraint)1 DropColumnStatement (liquibase.statement.core.DropColumnStatement)1 MarkChangeSetRanStatement (liquibase.statement.core.MarkChangeSetRanStatement)1