liquibase.change.ColumnConfig Java Examples

The following examples show how to use liquibase.change.ColumnConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HiveStandardChangeLogHistoryService.java    From liquibase-impala with Apache License 2.0 6 votes vote down vote up
@Override
    public void tag(final String tagString) throws DatabaseException {
        Database database = getDatabase();
        Executor executor = ExecutorService.getInstance().getExecutor(database);
        try {
            int totalRows = ExecutorService.getInstance().getExecutor(database).queryForInt(new SelectFromDatabaseChangeLogStatement(new ColumnConfig().setName("COUNT(*)", true)));
            if (totalRows == 0) {
                ChangeSet emptyChangeSet = new ChangeSet(String.valueOf(new Date().getTime()), "liquibase", false, false, "liquibase-internal", null, null, getDatabase().getObjectQuotingStrategy(), null);
                this.setExecType(emptyChangeSet, ChangeSet.ExecType.EXECUTED);
            }

//            Timestamp lastExecutedDate = (Timestamp) this.getExecutor().queryForObject(createChangeToTagSQL(), Timestamp.class);
            executor.execute(new TagDatabaseStatement(tagString));
            getDatabase().commit();

            if (this.ranChangeSetList != null) {
                ranChangeSetList.get(ranChangeSetList.size() - 1).setTag(tagString);
            }
        } catch (Exception e) {
            throw new DatabaseException(e);
        }
    }
 
Example #2
Source File: PerconaAddColumnChange.java    From liquibase-percona with Apache License 2.0 6 votes vote down vote up
@Override
protected Change[] createInverses() {
    List<Change> inverses = new ArrayList<Change>();

    for (ColumnConfig aColumn : getColumns()) {
        if (aColumn.hasDefaultValue()) {
            DropDefaultValueChange dropChange = new DropDefaultValueChange();
            dropChange.setTableName(getTableName());
            dropChange.setColumnName(aColumn.getName());
            dropChange.setSchemaName(getSchemaName());
            dropChange.setCatalogName(getCatalogName());
            inverses.add(dropChange);
        }

        // that's the percona drop column change.
        PerconaDropColumnChange inverse = new PerconaDropColumnChange();
        inverse.setSchemaName(getSchemaName());
        inverse.setColumnName(aColumn.getName());
        inverse.setCatalogName(getCatalogName());
        inverse.setTableName(getTableName());
        inverses.add(inverse);
    }

    return inverses.toArray(new Change[inverses.size()]);
}
 
Example #3
Source File: PerconaDropColumnChange.java    From liquibase-percona with Apache License 2.0 6 votes vote down vote up
@Override
public String generateAlterStatement(Database database) {
    StringBuilder alter = new StringBuilder();
    if (getColumns() != null && !getColumns().isEmpty()) {
        boolean first = true;
        for (ColumnConfig column : getColumns()) {
            if (!first) {
                alter.append(", ");
            }
            alter.append("DROP COLUMN ").append(column.getName());
            first = false;
        }
    } else {
        alter.append("DROP COLUMN ").append(getColumnName());
    }
    return alter.toString();
}
 
Example #4
Source File: CreateSpatialIndexChange.java    From liquibase-spatial with Apache License 2.0 6 votes vote down vote up
@Override
public SqlStatement[] generateStatements(final Database database) {
   final String[] columns = new String[this.columns.size()];
   int ii = 0;
   for (final ColumnConfig columnConfig : this.columns) {
      columns[ii++] = columnConfig.getName();
   }

   // Parse the string SRID into an integer.
   Integer srid = null;
   if (getSrid() != null) {
      srid = Integer.valueOf(getSrid());
   }

   final CreateSpatialIndexStatement statement = new CreateSpatialIndexStatement(
         getIndexName(), getCatalogName(), getSchemaName(), getTableName(), columns,
         getTablespace(), getGeometryType(), srid);
   return new SqlStatement[] { statement };
}
 
Example #5
Source File: PerconaDropColumnChangeTest.java    From liquibase-percona with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateAlterStatementMultipleColumns() {
    ColumnConfig col1 = new ColumnConfig();
    col1.setName("col1_test");
    getChange().addColumn(col1);
    ColumnConfig col2 = new ColumnConfig();
    col2.setName("col2_test");
    getChange().addColumn(col2);

    Assertions.assertEquals("DROP COLUMN col1_test, DROP COLUMN col2_test", getChange().generateAlterStatement(getDatabase()));
}
 
Example #6
Source File: CreateSpatialIndexChange.java    From liquibase-spatial with Apache License 2.0 5 votes vote down vote up
@Override
@DatabaseChangeProperty(mustEqualExisting = "index.column",
      description = "Column(s) to add to the index",
      requiredForDatabase = "all")
public List<ColumnConfig> getColumns() {
   if (this.columns == null) {
      return new ArrayList<ColumnConfig>();
   }
   return this.columns;
}
 
Example #7
Source File: HiveStandardChangeLogHistoryService.java    From liquibase-impala with Apache License 2.0 4 votes vote down vote up
private List<Map<String, ?>> queryDatabaseChangeLogTable(Database database) throws DatabaseException {
    SelectFromDatabaseChangeLogStatement select = new SelectFromDatabaseChangeLogStatement(new ColumnConfig().setName("*").setComputed(true)).setOrderBy("DATEEXECUTED ASC", "ORDEREXECUTED ASC");
    return ExecutorService.getInstance().getExecutor(database).queryForList(select);
}
 
Example #8
Source File: HiveStandardChangeLogHistoryService.java    From liquibase-impala with Apache License 2.0 4 votes vote down vote up
@Override
public boolean tagExists(final String tag) throws DatabaseException {
    int count = ExecutorService.getInstance().getExecutor(getDatabase()).queryForInt(new SelectFromDatabaseChangeLogStatement(new SelectFromDatabaseChangeLogStatement.ByTag(tag), new ColumnConfig().setName("COUNT(*)", true)));
    return count > 0;
}
 
Example #9
Source File: CreateSpatialIndexChange.java    From liquibase-spatial with Apache License 2.0 4 votes vote down vote up
@Override
public void setColumns(final List<ColumnConfig> columns) {
   this.columns = columns;
}
 
Example #10
Source File: CreateSpatialIndexChange.java    From liquibase-spatial with Apache License 2.0 4 votes vote down vote up
@Override
public void addColumn(final ColumnConfig column) {
   this.columns.add(column);
}
 
Example #11
Source File: CreateSpatialIndexChangeTest.java    From liquibase-spatial with Apache License 2.0 4 votes vote down vote up
/**
 * Tests {@link CreateSpatialIndexChange#validate(liquibase.database.Database)}.
 *
 * @param catalogName
 *           the name of the catalog.
 * @param schemaName
 *           the name of the schema.
 * @param tablespace
 *           the name of the tablespace.
 * @param tableName
 *           the name of the table.
 * @param columnName
 *           the geometry column name.
 * @param indexName
 *           the name of the spatial index.
 * @param geometryType
 *           the geometry type.
 * @param srid
 *           the Spatial Reference System ID.
 * @param database
 *           the database instance.
 * @param passes
 *           indicates if the test is expected to pass.
 */
@Test(dataProvider = "validateTestData")
public void testValidate(final String catalogName, final String schemaName,
      final String tablespace, final String tableName, final String columnName,
      final String indexName, final String geometryType, final String srid,
      final Database database, final boolean passes) {
   final CreateSpatialIndexChange change = new CreateSpatialIndexChange();
   change.setCatalogName(catalogName);
   change.setSchemaName(schemaName);
   change.setTablespace(tablespace);
   change.setTableName(tableName);
   final ColumnConfig column = new ColumnConfig();
   column.setName(columnName);
   change.addColumn(column);
   change.setIndexName(indexName);
   change.setGeometryType(geometryType);
   change.setSrid(srid);
   final ValidationErrors errors = change.validate(database);
   assertEquals(errors.hasErrors(), !passes, "Errors were " + (passes ? " not" : "")
         + "expected");
}