use of liquibase.change.core.DropColumnChange in project liquibase by liquibase.
the class UnexpectedColumnChangeGenerator method fixUnexpected.
@Override
public Change[] fixUnexpected(DatabaseObject unexpectedObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) {
Column column = (Column) unexpectedObject;
if (column.getComputed() != null && column.getComputed()) {
//not really a column to drop, probably part of an index or something
return null;
}
if (column.getRelation() instanceof View) {
return null;
}
if (column.getRelation().getSnapshotId() == null) {
//not an actual table, maybe an alias, maybe in a different schema. Don't fix it.
return null;
}
DropColumnChange change = new DropColumnChange();
change.setTableName(column.getRelation().getName());
if (control.getIncludeCatalog()) {
change.setCatalogName(column.getRelation().getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(column.getRelation().getSchema().getName());
}
change.setColumnName(column.getName());
return new Change[] { change };
}
use of liquibase.change.core.DropColumnChange in project liquibase by liquibase.
the class DropColumnChangeTest method generateStatements_multipleColumns.
@Test
public void generateStatements_multipleColumns() {
DropColumnChange change = new DropColumnChange();
ColumnConfig column1 = new ColumnConfig();
column1.setName("column1");
change.addColumn(column1);
ColumnConfig column2 = new ColumnConfig();
column2.setName("column2");
change.addColumn(column2);
SqlStatement[] statements = change.generateStatements(new MockDatabase());
Assert.assertEquals(1, statements.length);
Assert.assertTrue(statements[0] instanceof DropColumnStatement);
DropColumnStatement stmt = (DropColumnStatement) statements[0];
Assert.assertTrue(stmt.isMultiple());
Assert.assertEquals(2, stmt.getColumns().size());
}
Aggregations