use of liquibase.structure.core.Index in project liquibase by liquibase.
the class RenameColumnChange method generateStatementsForSQLiteDatabase.
private SqlStatement[] generateStatementsForSQLiteDatabase(Database database) {
// SQLite does not support this ALTER TABLE operation until now.
// For more information see: http://www.sqlite.org/omitted.html.
// This is a small work around...
List<SqlStatement> statements = new ArrayList<SqlStatement>();
// define alter table logic
AlterTableVisitor rename_alter_visitor = new AlterTableVisitor() {
@Override
public ColumnConfig[] getColumnsToAdd() {
return new ColumnConfig[0];
}
@Override
public boolean copyThisColumn(ColumnConfig column) {
return true;
}
@Override
public boolean createThisColumn(ColumnConfig column) {
if (column.getName().equals(getOldColumnName())) {
column.setName(getNewColumnName());
}
return true;
}
@Override
public boolean createThisIndex(Index index) {
if (index.getColumnNames().contains(getOldColumnName())) {
Iterator<Column> columnIterator = index.getColumns().iterator();
while (columnIterator.hasNext()) {
Column column = columnIterator.next();
if (column.getName().equals(getOldColumnName())) {
columnIterator.remove();
break;
}
}
index.addColumn(new Column(getNewColumnName()).setRelation(index.getTable()));
}
return true;
}
};
try {
// alter table
statements.addAll(SQLiteDatabase.getAlterTableStatements(rename_alter_visitor, database, getCatalogName(), getSchemaName(), getTableName()));
} catch (Exception e) {
System.err.println(e);
e.printStackTrace();
}
return statements.toArray(new SqlStatement[statements.size()]);
}
use of liquibase.structure.core.Index in project liquibase by liquibase.
the class CreateIndexChange method checkStatus.
@Override
public ChangeStatus checkStatus(Database database) {
ChangeStatus result = new ChangeStatus();
try {
Index example = new Index(getIndexName(), getCatalogName(), getSchemaName(), getTableName());
if (getColumns() != null) {
for (ColumnConfig column : getColumns()) {
example.addColumn(new Column(column));
}
}
Index snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(example, database);
result.assertComplete(snapshot != null, "Index does not exist");
if (snapshot != null) {
if (isUnique() != null) {
result.assertCorrect(isUnique().equals(snapshot.isUnique()), "Unique does not match");
}
}
return result;
} catch (Exception e) {
return result.unknown(e);
}
}
Aggregations