use of liquibase.statement.core.AddColumnStatement in project liquibase by liquibase.
the class AddColumnChangeTest method generateStatements_multipleColumns.
@Test
public void generateStatements_multipleColumns() {
AddColumnChange change = new AddColumnChange();
AddColumnConfig column1 = new AddColumnConfig();
column1.setName("column1");
column1.setType("INT");
change.addColumn(column1);
AddColumnConfig column2 = new AddColumnConfig();
column2.setName("column2");
column2.setType("INT");
change.addColumn(column2);
SqlStatement[] statements = change.generateStatements(new MockDatabase());
Assert.assertEquals(1, statements.length);
Assert.assertTrue(statements[0] instanceof AddColumnStatement);
AddColumnStatement stmt = (AddColumnStatement) statements[0];
Assert.assertTrue(stmt.isMultiple());
Assert.assertEquals(2, stmt.getColumns().size());
}
use of liquibase.statement.core.AddColumnStatement in project liquibase by liquibase.
the class AddColumnGenerator method validate.
@Override
public ValidationErrors validate(AddColumnStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
if (statement.isMultiple()) {
ValidationErrors validationErrors = new ValidationErrors();
AddColumnStatement firstColumn = statement.getColumns().get(0);
for (AddColumnStatement column : statement.getColumns()) {
validationErrors.addAll(validateSingleColumn(column, database));
if (firstColumn.getTableName() != null && !firstColumn.getTableName().equals(column.getTableName())) {
validationErrors.addError("All columns must be targeted at the same table");
}
if (column.isMultiple()) {
validationErrors.addError("Nested multiple add column statements are not supported");
}
}
return validationErrors;
} else {
return validateSingleColumn(statement, database);
}
}
Aggregations