liquibase.statement.SqlStatement Java Examples

The following examples show how to use liquibase.statement.SqlStatement. 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: 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 #2
Source File: CustomLockService.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private Set<Integer> currentIdsInDatabaseChangeLogLockTable() throws DatabaseException {
    try {
        Executor executor = ExecutorService.getInstance().getExecutor(database);
        String idColumnName = database.escapeColumnName(database.getLiquibaseCatalogName(),
                database.getLiquibaseSchemaName(),
                database.getDatabaseChangeLogLockTableName(),
                "ID");
        String lockTableName = database.escapeTableName(database.getLiquibaseCatalogName(),
                database.getLiquibaseSchemaName(),
                database.getDatabaseChangeLogLockTableName());
        SqlStatement sqlStatement = new RawSqlStatement("SELECT " + idColumnName + " FROM " + lockTableName);
        List<Map<String, ?>> rows = executor.queryForList(sqlStatement);
        Set<Integer> ids = rows.stream().map(columnMap -> ((Number) columnMap.get("ID")).intValue()).collect(Collectors.toSet());
        database.commit();
        return ids;
    } catch (UnexpectedLiquibaseException ulie) {
        // It can happen with MariaDB Galera 10.1 that UnexpectedLiquibaseException is rethrown due the DB lock.
        // It is sufficient to just rollback transaction and retry in that case.
        if (ulie.getCause() != null && ulie.getCause() instanceof DatabaseException) {
            throw (DatabaseException) ulie.getCause();
        } else {
            throw ulie;
        }
    }
}
 
Example #3
Source File: AbstractJdbcDatabase.java    From jweb-cms with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void execute(final SqlStatement[] statements, final List<SqlVisitor> sqlVisitors) throws LiquibaseException {
    for (SqlStatement statement : statements) {
        if (statement.skipOnUnsupported() && !SqlGeneratorFactory.getInstance().supports(statement, this)) {
            continue;
        }
        LogService.getLog(getClass()).debug(LogType.LOG, "Executing Statement: " + statement);
        try {
            ExecutorService.getInstance().getExecutor(this).execute(statement, sqlVisitors);
        } catch (DatabaseException e) {
            if (statement.continueOnError()) {
                LogService.getLog(getClass()).severe(LogType.LOG, "Error executing statement '" + statement.toString() + "', but continuing", e);
            } else {
                throw e;
            }
        }
    }
}
 
Example #4
Source File: AddPrimaryKeyChangeMSSQL.java    From liquibase-mssql with Apache License 2.0 6 votes vote down vote up
@Override
public SqlStatement[] generateStatements(Database database) {
  SqlStatement[] statements = super.generateStatements(database);
  if (!MSSQLDatabase.PRODUCT_NAME.equals(database.getDatabaseProductName())) {
  	return statements;
  }
  List<SqlStatement> extendedStatements = new ArrayList<SqlStatement>(statements.length);

  for (SqlStatement statement : statements) {
    if (statement instanceof AddPrimaryKeyStatement) {
      extendedStatements.add(new AddPrimaryKeyStatementMSSQL((AddPrimaryKeyStatement)statement, fillFactor));
    } else {
      extendedStatements.add(statement);
    }
  }

  return extendedStatements.toArray(new SqlStatement[0]);
}
 
Example #5
Source File: AbstractJdbcDatabase.java    From jweb-cms with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Overwrite this method to get the default schema name for the connection.
 * If you only need to change the statement that obtains the current schema then override
 *
 * @see AbstractJdbcDatabase#getConnectionSchemaNameCallStatement()
 */
protected String getConnectionSchemaName() {
    if (connection == null) {
        return null;
    }
    if (connection instanceof OfflineConnection) {
        return ((OfflineConnection) connection).getSchema();
    }

    try {
        SqlStatement currentSchemaStatement = getConnectionSchemaNameCallStatement();
        return ExecutorService.getInstance().getExecutor(this).
            queryForObject(currentSchemaStatement, String.class);
    } catch (Exception e) {
        LogService.getLog(getClass()).info(LogType.LOG, "Error getting default schema", e);
    }
    return null;
}
 
Example #6
Source File: LoadDataChangeMSSQL.java    From liquibase-mssql with Apache License 2.0 6 votes vote down vote up
@Override
   public SqlStatement[] generateStatements(Database database) {
SqlStatement[] statements = super.generateStatements(database);
   if (!MSSQLDatabase.PRODUCT_NAME.equals(database.getDatabaseProductName())) {
   	return statements;
   }
List<SqlStatement> wrappedStatements = new ArrayList<SqlStatement>(statements.length);
for (SqlStatement statement : statements) {
    if (statement instanceof InsertStatement) {
	wrappedStatements.add(new InsertStatementMSSQL((InsertStatement) statement, identityInsertEnabled));
    } else if(statement instanceof InsertSetStatement) {
        wrappedStatements.add(new InsertSetStatementMSSQL((InsertSetStatement) statement, identityInsertEnabled));
    } else {
	wrappedStatements.add(statement);
    }
}
return wrappedStatements.toArray(new SqlStatement[0]);
   }
 
Example #7
Source File: CreateIndexChangeMSSQL.java    From liquibase-mssql with Apache License 2.0 6 votes vote down vote up
@Override
public SqlStatement[] generateStatements(Database database) {
  SqlStatement[] statements = super.generateStatements(database);
  if (!MSSQLDatabase.PRODUCT_NAME.equals(database.getDatabaseProductName())) {
  	return statements;
  }

  List<SqlStatement> extendedStatements = new ArrayList<SqlStatement>(statements.length);
  for (SqlStatement statement : statements) {
    if (statement instanceof CreateIndexStatement) {
      extendedStatements.add(new CreateIndexStatementMSSQL((CreateIndexStatement)statement, includedColumns, fillFactor));
    } else {
      extendedStatements.add(statement);
    }
  }

  return extendedStatements.toArray(new SqlStatement[0]);
}
 
Example #8
Source File: InsertDataChangeMSSQL.java    From liquibase-mssql with Apache License 2.0 6 votes vote down vote up
@Override
public SqlStatement[] generateStatements(Database database) {
    SqlStatement[] statements = super.generateStatements(database);
    if (!MSSQLDatabase.PRODUCT_NAME.equals(database.getDatabaseProductName())) {
    	return statements;
    }
    List<SqlStatement> wrappedStatements = new ArrayList<SqlStatement>(statements.length);
    for (SqlStatement statement : statements) {
        if (statement instanceof InsertStatement) {
            wrappedStatements.add(new InsertStatementMSSQL((InsertStatement) statement, identityInsertEnabled));
        } else {
            wrappedStatements.add(statement);
        }
    }
    return wrappedStatements.toArray(new SqlStatement[0]);
}
 
Example #9
Source File: DropSpatialIndexChange.java    From liquibase-spatial with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a {@link DropSpatialIndexStatement} followed by a {@link DropIndexStatement}, if
 * applicable. The first statement allows extra clean-up when dropping an index. The second
 * statement leverages the normal <code>DROP INDEX</code> logic.
 */
@Override
public SqlStatement[] generateStatements(final Database database) {
   final Collection<SqlStatement> statements = new ArrayList<SqlStatement>();
   // MySQL and PostgreSQL only need the normal DROP INDEX statement.
   if (!(database instanceof MySQLDatabase) && !(database instanceof PostgresDatabase)) {
      final DropSpatialIndexStatement dropSpatialIndex = new DropSpatialIndexStatement(
            this.indexName, this.catalogName, this.schemaName, this.tableName);
      statements.add(dropSpatialIndex);
   }

   // GeoDB doesn't use a tradition index structure so don't issue the normal DROP INDEX
   // statement.
   if (!(database instanceof DerbyDatabase) && !(database instanceof H2Database)) {
      final DropIndexStatement dropIndex = new DropIndexStatement(this.indexName,
            this.catalogName, this.schemaName, this.tableName, null);
      statements.add(dropIndex);
   }
   return statements.toArray(new SqlStatement[statements.size()]);
}
 
Example #10
Source File: PerconaDropForeignKeyConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSQL() {
    enableLogging();

    SqlStatement[] statements = generateStatements();
    Assertions.assertEquals(3, statements.length);
    Assertions.assertEquals(CommentStatement.class, statements[0].getClass());
    Assertions.assertEquals("pt-online-schema-change "
            + "--alter-foreign-keys-method=auto "
            + "--nocheck-unique-key-change "
            + "--alter=\"" + alterText + "\" "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=address",
            ((CommentStatement)statements[0]).getText());
    Assertions.assertEquals(CommentStatement.class, statements[1].getClass());
    Assertions.assertEquals(DropForeignKeyConstraintStatement.class, statements[2].getClass());
}
 
Example #11
Source File: PerconaAddUniqueConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSQL() {
    enableLogging();

    SqlStatement[] statements = generateStatements();
    Assertions.assertEquals(3, statements.length);
    Assertions.assertEquals(CommentStatement.class, statements[0].getClass());
    Assertions.assertEquals("pt-online-schema-change "
            + "--alter-foreign-keys-method=auto "
            + "--nocheck-unique-key-change "
            + "--alter=\"" + alterText + "\" "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person",
            ((CommentStatement)statements[0]).getText());
    Assertions.assertEquals(CommentStatement.class, statements[1].getClass());
    Assertions.assertEquals(AddUniqueConstraintStatement.class, statements[2].getClass());
}
 
Example #12
Source File: PerconaAddUniqueConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 6 votes vote down vote up
@Test
public void testRollbackSQL() throws RollbackImpossibleException {
    enableLogging();

    SqlStatement[] statements = generateRollbackStatements();
    Assertions.assertEquals(3, statements.length);
    Assertions.assertEquals(CommentStatement.class, statements[0].getClass());
    Assertions.assertEquals("pt-online-schema-change "
            + "--alter-foreign-keys-method=auto "
            + "--nocheck-unique-key-change "
            + "--alter=\"" + alterRollbackText + "\" "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person",
            ((CommentStatement)statements[0]).getText());
    Assertions.assertEquals(CommentStatement.class, statements[1].getClass());
    Assertions.assertEquals(DropUniqueConstraintStatement.class, statements[2].getClass());
}
 
Example #13
Source File: PerconaDropUniqueConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSQL() {
    enableLogging();

    SqlStatement[] statements = generateStatements();
    Assertions.assertEquals(3, statements.length);
    Assertions.assertEquals(CommentStatement.class, statements[0].getClass());
    Assertions.assertEquals("pt-online-schema-change "
            + "--alter-foreign-keys-method=auto "
            + "--nocheck-unique-key-change "
            + "--alter=\"" + alterText + "\" "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person",
            ((CommentStatement)statements[0]).getText());
    Assertions.assertEquals(CommentStatement.class, statements[1].getClass());
    Assertions.assertEquals(DropUniqueConstraintStatement.class, statements[2].getClass());
}
 
Example #14
Source File: PerconaDropColumnChangeTest.java    From liquibase-percona with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSQL() {
    enableLogging();

    SqlStatement[] statements = generateStatements();
    Assertions.assertEquals(3, statements.length);
    Assertions.assertEquals(CommentStatement.class, statements[0].getClass());
    Assertions.assertEquals("pt-online-schema-change "
            + "--alter-foreign-keys-method=auto "
            + "--nocheck-unique-key-change "
            + "--alter=\"DROP COLUMN col_test\" "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person",
            ((CommentStatement)statements[0]).getText());
    Assertions.assertEquals(CommentStatement.class, statements[1].getClass());
    Assertions.assertEquals(DropColumnStatement.class, statements[2].getClass());
}
 
Example #15
Source File: PerconaCreateIndexChangeTest.java    From liquibase-percona with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSQL() {
    enableLogging();

    SqlStatement[] statements = generateStatements();
    Assertions.assertEquals(3, statements.length);
    Assertions.assertEquals(CommentStatement.class, statements[0].getClass());
    Assertions.assertEquals("pt-online-schema-change "
            + "--alter-foreign-keys-method=auto "
            + "--nocheck-unique-key-change "
            + "--alter=\"ADD UNIQUE INDEX theIndexName (indexedColumn)\" "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person",
            ((CommentStatement)statements[0]).getText());
    Assertions.assertEquals(CommentStatement.class, statements[1].getClass());
    Assertions.assertEquals(CreateIndexStatement.class, statements[2].getClass());
}
 
Example #16
Source File: PerconaAddForeignKeyConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSQL() {
    enableLogging();

    SqlStatement[] statements = generateStatements();
    Assertions.assertEquals(3, statements.length);
    Assertions.assertEquals(CommentStatement.class, statements[0].getClass());
    Assertions.assertEquals("pt-online-schema-change "
            + "--alter-foreign-keys-method=auto "
            + "--nocheck-unique-key-change "
            + "--alter=\"" + alterText + "\" "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=address",
            ((CommentStatement)statements[0]).getText());
    Assertions.assertEquals(CommentStatement.class, statements[1].getClass());
    Assertions.assertEquals(AddForeignKeyConstraintStatement.class, statements[2].getClass());
}
 
Example #17
Source File: PerconaAddForeignKeyConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 6 votes vote down vote up
@Test
public void testRollbackSQL() throws RollbackImpossibleException {
    enableLogging();

    SqlStatement[] statements = generateRollbackStatements();
    Assertions.assertEquals(3, statements.length);
    Assertions.assertEquals(CommentStatement.class, statements[0].getClass());
    Assertions.assertEquals("pt-online-schema-change "
            + "--alter-foreign-keys-method=auto "
            + "--nocheck-unique-key-change "
            + "--alter=\"" + alterRollbackText + "\" "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=address",
            ((CommentStatement)statements[0]).getText());
    Assertions.assertEquals(CommentStatement.class, statements[1].getClass());
    Assertions.assertEquals(DropForeignKeyConstraintStatement.class, statements[2].getClass());
}
 
Example #18
Source File: PerconaAddColumnChangeTest.java    From liquibase-percona with Apache License 2.0 6 votes vote down vote up
@Test
public void testRollbackSQL() throws RollbackImpossibleException {
    enableLogging();

    SqlStatement[] statements = generateRollbackStatements();
    Assertions.assertEquals(3, statements.length);
    Assertions.assertEquals(CommentStatement.class, statements[0].getClass());
    Assertions.assertEquals("pt-online-schema-change "
            + "--alter-foreign-keys-method=auto "
            + "--nocheck-unique-key-change "
            + "--alter=\"DROP COLUMN new_column\" "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person",
            ((CommentStatement)statements[0]).getText());
    Assertions.assertEquals(CommentStatement.class, statements[1].getClass());
    Assertions.assertEquals(DropColumnStatement.class, statements[2].getClass());
}
 
Example #19
Source File: PerconaAddColumnChangeTest.java    From liquibase-percona with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSQL() {
    enableLogging();

    SqlStatement[] statements = generateStatements();
    Assertions.assertEquals(3, statements.length);
    Assertions.assertEquals(CommentStatement.class, statements[0].getClass());
    Assertions.assertEquals("pt-online-schema-change "
            + "--alter-foreign-keys-method=auto "
            + "--nocheck-unique-key-change "
            + "--alter=\"ADD COLUMN new_column INT NULL\" "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person",
            ((CommentStatement)statements[0]).getText());
    Assertions.assertEquals(CommentStatement.class, statements[1].getClass());
    Assertions.assertEquals(AddColumnStatement.class, statements[2].getClass());
}
 
Example #20
Source File: PerconaAddForeignKeyConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 5 votes vote down vote up
@Test
public void testSkipAddForeignKeyConstraintChange() {
    System.setProperty(Configuration.SKIP_CHANGES, "addForeignKeyConstraint");
    SqlStatement[] statements = generateStatements();
    Assertions.assertEquals(1, statements.length);
    Assertions.assertEquals(AddForeignKeyConstraintStatement.class, statements[0].getClass());
}
 
Example #21
Source File: AddRealmCodeSecret.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public SqlStatement[] generateStatements(Database database) throws CustomChangeException {
    try {
        StringBuilder sb = new StringBuilder();
        sb.append("Generated codeSecret for realms: ");

        Connection connection = ((JdbcConnection) (database.getConnection())).getWrappedConnection();
        ArrayList<SqlStatement> statements = new ArrayList<SqlStatement>();

        String correctedTableName = database.correctObjectName("REALM", Table.class);
        String correctedSchemaName = database.escapeObjectName(database.getDefaultSchemaName(), Schema.class);

        if (SnapshotGeneratorFactory.getInstance().has(new Table().setName(correctedTableName), database)) {
            try (Statement st = connection.createStatement(); ResultSet resultSet = st.executeQuery("SELECT ID FROM " + LiquibaseJpaUpdaterProvider.getTable(correctedTableName, correctedSchemaName) + " WHERE CODE_SECRET IS NULL")) {
                while (resultSet.next()) {
                    String id = resultSet.getString(1);
                    
                    UpdateStatement statement = new UpdateStatement(null, null, correctedTableName)
                            .addNewColumnValue("CODE_SECRET", KeycloakModelUtils.generateCodeSecret())
                            .setWhereClause("ID=?").addWhereParameters(id);
                    statements.add(statement);
                    
                    if (!resultSet.isFirst()) {
                        sb.append(", ");
                    }
                    sb.append(id);
                }

                if (!statements.isEmpty()) {
                    confirmationMessage = sb.toString();
                }
            }
        }

        return statements.toArray(new SqlStatement[statements.size()]);
    } catch (Exception e) {
        throw new CustomChangeException("Failed to add realm code secret", e);
    }
}
 
Example #22
Source File: PerconaDropUniqueConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithoutPercona() {
    PTOnlineSchemaChangeStatement.available = false;
    SqlStatement[] statements = generateStatements();
    Assertions.assertEquals(1, statements.length);
    Assertions.assertEquals(DropUniqueConstraintStatement.class, statements[0].getClass());
}
 
Example #23
Source File: PerconaAddUniqueConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 5 votes vote down vote up
@Test
public void testSkipAddUniqueConstraintChange() {
    System.setProperty(Configuration.SKIP_CHANGES, "addUniqueConstraint");
    SqlStatement[] statements = generateStatements();
    Assertions.assertEquals(1, statements.length);
    Assertions.assertEquals(AddUniqueConstraintStatement.class, statements[0].getClass());
}
 
Example #24
Source File: PerconaAddUniqueConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 5 votes vote down vote up
@Test
public void testRollbackSQLNoAlterSqlDryMode() throws RollbackImpossibleException {
    enableLogging();
    System.setProperty(Configuration.NO_ALTER_SQL_DRY_MODE, "true");

    SqlStatement[] statements = generateRollbackStatements();
    Assertions.assertEquals(1, statements.length);
    Assertions.assertEquals(CommentStatement.class, statements[0].getClass());
    Assertions.assertEquals("pt-online-schema-change "
            + "--alter-foreign-keys-method=auto "
            + "--nocheck-unique-key-change "
            + "--alter=\"" + alterRollbackText + "\" "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person",
            ((CommentStatement)statements[0]).getText());
}
 
Example #25
Source File: PerconaAddUniqueConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateSQLNoAlterSqlDryMode() {
    enableLogging();
    System.setProperty(Configuration.NO_ALTER_SQL_DRY_MODE, "true");

    SqlStatement[] statements = generateStatements();
    Assertions.assertEquals(1, statements.length);
    Assertions.assertEquals(CommentStatement.class, statements[0].getClass());
    Assertions.assertEquals("pt-online-schema-change "
            + "--alter-foreign-keys-method=auto "
            + "--nocheck-unique-key-change "
            + "--alter=\"" + alterText + "\" "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person",
            ((CommentStatement)statements[0]).getText());
}
 
Example #26
Source File: CustomKeycloakTask.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public SqlStatement[] generateStatements(Database database) throws CustomChangeException {
    this.database = database;
    jdbcConnection = (JdbcConnection) database.getConnection();
    connection = jdbcConnection.getWrappedConnection();

    if (isApplicable()) {
        confirmationMessage.append(getTaskId() + ": ");
        generateStatementsImpl();
    } else {
        confirmationMessage.append(getTaskId() + ": no update applicable for this task");
    }

    return statements.toArray(new SqlStatement[statements.size()]);
}
 
Example #27
Source File: AbstractJdbcDatabase.java    From jweb-cms with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void saveRollbackStatement(final Change change, final List<SqlVisitor> sqlVisitors, final Writer writer) throws IOException, LiquibaseException {
    SqlStatement[] statements = change.generateRollbackStatements(this);
    for (SqlStatement statement : statements) {
        for (Sql sql : SqlGeneratorFactory.getInstance().generateSql(statement, this)) {
            writer.append(sql.toSql()).append(sql.getEndDelimiter()).append("\n\n");
        }
    }
}
 
Example #28
Source File: PerconaAddUniqueConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithoutPerconaRollback() throws RollbackImpossibleException {
    PTOnlineSchemaChangeStatement.available = false;
    SqlStatement[] statements = generateRollbackStatements();
    Assertions.assertEquals(1, statements.length);
    Assertions.assertEquals(DropUniqueConstraintStatement.class, statements[0].getClass());
}
 
Example #29
Source File: PerconaAddUniqueConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithoutPercona() {
    PTOnlineSchemaChangeStatement.available = false;
    SqlStatement[] statements = generateStatements();
    Assertions.assertEquals(1, statements.length);
    Assertions.assertEquals(AddUniqueConstraintStatement.class, statements[0].getClass());
}
 
Example #30
Source File: PerconaDropUniqueConstraintChangeTest.java    From liquibase-percona with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateSQLNoAlterSqlDryMode() {
    enableLogging();
    System.setProperty(Configuration.NO_ALTER_SQL_DRY_MODE, "true");

    SqlStatement[] statements = generateStatements();
    Assertions.assertEquals(1, statements.length);
    Assertions.assertEquals(CommentStatement.class, statements[0].getClass());
    Assertions.assertEquals("pt-online-schema-change "
            + "--alter-foreign-keys-method=auto "
            + "--nocheck-unique-key-change "
            + "--alter=\"" + alterText + "\" "
            + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person",
            ((CommentStatement)statements[0]).getText());
}