Search in sources :

Example 1 with DropColumnChange

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 };
}
Also used : DropColumnChange(liquibase.change.core.DropColumnChange) DropColumnChange(liquibase.change.core.DropColumnChange) Change(liquibase.change.Change)

Example 2 with DropColumnChange

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());
}
Also used : DropColumnChange(liquibase.change.core.DropColumnChange) SqlStatement(liquibase.statement.SqlStatement) MockDatabase(liquibase.sdk.database.MockDatabase) DropColumnStatement(liquibase.statement.core.DropColumnStatement) Test(org.junit.Test)

Aggregations

DropColumnChange (liquibase.change.core.DropColumnChange)2 Change (liquibase.change.Change)1 MockDatabase (liquibase.sdk.database.MockDatabase)1 SqlStatement (liquibase.statement.SqlStatement)1 DropColumnStatement (liquibase.statement.core.DropColumnStatement)1 Test (org.junit.Test)1