Search in sources :

Example 6 with DropColumnStatement

use of liquibase.statement.core.DropColumnStatement in project liquibase by liquibase.

the class DropColumnChange method generateMultipeColumns.

private SqlStatement[] generateMultipeColumns(Database database) {
    List<SqlStatement> statements = new ArrayList<SqlStatement>();
    List<DropColumnStatement> dropStatements = new ArrayList<DropColumnStatement>();
    for (ColumnConfig column : columns) {
        if (database instanceof SQLiteDatabase) {
            statements.addAll(Arrays.asList(generateStatementsForSQLiteDatabase(database, column.getName())));
        } else {
            dropStatements.add(new DropColumnStatement(getCatalogName(), getSchemaName(), getTableName(), column.getName()));
        }
    }
    if (dropStatements.size() == 1) {
        statements.add(dropStatements.get(0));
    } else {
        statements.add(new DropColumnStatement(dropStatements));
    }
    if (database instanceof DB2Database) {
        statements.add(new ReorganizeTableStatement(getCatalogName(), getSchemaName(), getTableName()));
    }
    return statements.toArray(new SqlStatement[statements.size()]);
}
Also used : DB2Database(liquibase.database.core.DB2Database) SqlStatement(liquibase.statement.SqlStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) ReorganizeTableStatement(liquibase.statement.core.ReorganizeTableStatement) ArrayList(java.util.ArrayList) DropColumnStatement(liquibase.statement.core.DropColumnStatement)

Aggregations

DropColumnStatement (liquibase.statement.core.DropColumnStatement)6 ArrayList (java.util.ArrayList)3 SqlStatement (liquibase.statement.SqlStatement)3 DB2Database (liquibase.database.core.DB2Database)2 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)2 Sql (liquibase.sql.Sql)2 ReorganizeTableStatement (liquibase.statement.core.ReorganizeTableStatement)2 Test (org.junit.Test)2 DropColumnChange (liquibase.change.core.DropColumnChange)1 MySQLDatabase (liquibase.database.core.MySQLDatabase)1 ValidationErrors (liquibase.exception.ValidationErrors)1 MockDatabase (liquibase.sdk.database.MockDatabase)1 UnparsedSql (liquibase.sql.UnparsedSql)1 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)1 MockSqlGeneratorChain (liquibase.sqlgenerator.MockSqlGeneratorChain)1