Search in sources :

Example 11 with AddColumnConfig

use of liquibase.change.AddColumnConfig in project liquibase by liquibase.

the class MissingIndexChangeGenerator method fixMissing.

@Override
public Change[] fixMissing(DatabaseObject missingObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) {
    Index index = (Index) missingObject;
    if (comparisonDatabase instanceof MSSQLDatabase) {
        PrimaryKey primaryKey = index.getTable().getPrimaryKey();
        if (primaryKey != null && DatabaseObjectComparatorFactory.getInstance().isSameObject(missingObject, primaryKey.getBackingIndex(), control.getSchemaComparisons(), referenceDatabase)) {
            //will be handled by the PK
            return new Change[0];
        }
    }
    CreateIndexChange change = createCreateIndexChange();
    change.setTableName(index.getTable().getName());
    if (control.getIncludeTablespace()) {
        change.setTablespace(index.getTablespace());
    }
    if (control.getIncludeCatalog()) {
        change.setCatalogName(index.getTable().getSchema().getCatalogName());
    }
    if (control.getIncludeSchema()) {
        change.setSchemaName(index.getTable().getSchema().getName());
    }
    change.setIndexName(index.getName());
    change.setUnique(index.isUnique() != null && index.isUnique() ? Boolean.TRUE : null);
    change.setAssociatedWith(index.getAssociatedWithAsString());
    change.setClustered(index.getClustered() != null && index.getClustered() ? Boolean.TRUE : null);
    for (Column column : index.getColumns()) {
        change.addColumn(new AddColumnConfig(column));
    }
    return new Change[] { change };
}
Also used : Column(liquibase.structure.core.Column) PrimaryKey(liquibase.structure.core.PrimaryKey) Index(liquibase.structure.core.Index) AddColumnConfig(liquibase.change.AddColumnConfig) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Change(liquibase.change.Change) CreateIndexChange(liquibase.change.core.CreateIndexChange) CreateIndexChange(liquibase.change.core.CreateIndexChange)

Aggregations

AddColumnConfig (liquibase.change.AddColumnConfig)11 Test (org.junit.Test)4 Change (liquibase.change.Change)3 AddColumnChange (liquibase.change.core.AddColumnChange)3 CreateIndexChange (liquibase.change.core.CreateIndexChange)2 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)2 Difference (liquibase.diff.Difference)2 Sql (liquibase.sql.Sql)2 UnparsedSql (liquibase.sql.UnparsedSql)2 SqlStatement (liquibase.statement.SqlStatement)2 Column (liquibase.structure.core.Column)2 Index (liquibase.structure.core.Index)2 Element (org.w3c.dom.Element)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 CatalogAndSchema (liquibase.CatalogAndSchema)1 ColumnConfig (liquibase.change.ColumnConfig)1 ConstraintsConfig (liquibase.change.ConstraintsConfig)1 CreateTableChange (liquibase.change.core.CreateTableChange)1