use of liquibase.sqlgenerator.SqlGeneratorFactory in project liquibase by liquibase.
the class AddColumnGeneratorTest method testAddColumnWithNotNullConstraintAndValue.
@Test
public void testAddColumnWithNotNullConstraintAndValue() {
AddColumnChange change = new AddColumnChange();
change.setTableName(TABLE_NAME);
AddColumnConfig column = new AddColumnConfig();
column.setName("column1");
column.setType("int8");
column.setValueNumeric("0");
column.setConstraints(new ConstraintsConfig().setNullable(false));
change.addColumn(column);
AddColumnConfig column2 = new AddColumnConfig();
column2.setName("column2");
column2.setType("boolean");
column2.setValueBoolean("true");
column2.setConstraints(new ConstraintsConfig().setNullable(false));
change.addColumn(column2);
SqlStatement[] statements = change.generateStatements(new MySQLDatabase());
SqlGeneratorFactory instance = SqlGeneratorFactory.getInstance();
Sql[] sql = instance.generateSql(statements, new MySQLDatabase());
assertEquals(5, sql.length);
assertEquals("ALTER TABLE table_name ADD column1 BIGINT NULL, ADD column2 BIT(1) NULL", sql[0].toSql());
assertEquals("UPDATE table_name SET column1 = 0", sql[1].toSql());
assertEquals("UPDATE table_name SET column2 = 1", sql[2].toSql());
assertEquals("ALTER TABLE table_name MODIFY column1 BIGINT NOT NULL", sql[3].toSql());
assertEquals("ALTER TABLE table_name MODIFY column2 BIT(1) NOT NULL", sql[4].toSql());
}
Aggregations