Search in sources :

Example 6 with Table

use of org.flywaydb.core.internal.database.base.Table in project flyway by flyway.

the class InformixSchema method doClean.

@Override
protected void doClean() throws SQLException {
    List<String> procedures = jdbcTemplate.queryForStringList("SELECT t.procname FROM \"informix\".sysprocedures AS t" + " WHERE t.owner=? AND t.mode='O' AND t.externalname IS NULL" + " AND t.procname NOT IN (" + // Exclude Informix TimeSeries procs
    " 'tscontainerusage', 'tscontainertotalused', 'tscontainertotalpages'," + " 'tscontainernelems', 'tscontainerpctused', 'tsl_flushstatus', 'tsmakenullstamp'" + ")", name);
    for (String procedure : procedures) {
        jdbcTemplate.execute("DROP PROCEDURE " + procedure);
    }
    for (Table table : allTables()) {
        table.drop();
    }
    List<String> sequences = jdbcTemplate.queryForStringList("SELECT t.tabname FROM \"informix\".systables AS t" + " WHERE owner=? AND t.tabid > 99 AND t.tabtype='Q'" + " AND t.tabname NOT IN ('iot_data_seq')", name);
    for (String sequence : sequences) {
        jdbcTemplate.execute("DROP SEQUENCE " + sequence);
    }
}
Also used : Table(org.flywaydb.core.internal.database.base.Table)

Example 7 with Table

use of org.flywaydb.core.internal.database.base.Table in project flyway by flyway.

the class SQLiteSchema method doEmpty.

@Override
protected boolean doEmpty() {
    Table[] tables = allTables();
    List<String> tableNames = new ArrayList<>();
    for (Table table : tables) {
        String tableName = table.getName();
        if (!IGNORED_SYSTEM_TABLE_NAMES.contains(tableName)) {
            tableNames.add(tableName);
        }
    }
    return tableNames.isEmpty();
}
Also used : Table(org.flywaydb.core.internal.database.base.Table) ArrayList(java.util.ArrayList)

Example 8 with Table

use of org.flywaydb.core.internal.database.base.Table in project flyway by flyway.

the class SpannerSchema method doClean.

@Override
protected void doClean() throws SQLException {
    List<String> statements = new ArrayList<>();
    for (String[] foreignKeyAndTable : doAllForeignKeys()) {
        String foreignKey = foreignKeyAndTable[0];
        String table = foreignKeyAndTable[1];
        statements.add("ALTER TABLE " + table + " DROP CONSTRAINT " + foreignKey);
    }
    for (String statement : statements) {
        jdbcTemplate.execute(statement);
    }
    statements.clear();
    for (Table table : doAllTables()) {
        for (String index : doAllIndexes(table)) {
            if (!index.equalsIgnoreCase("PRIMARY_KEY")) {
                jdbcTemplate.execute("DROP INDEX " + index);
            }
        }
        statements.add("DROP TABLE " + table);
    }
    for (String statement : statements) {
        jdbcTemplate.execute(statement);
    }
}
Also used : Table(org.flywaydb.core.internal.database.base.Table) ArrayList(java.util.ArrayList)

Example 9 with Table

use of org.flywaydb.core.internal.database.base.Table in project flyway by flyway.

the class IgniteThinSchema method doClean.

@Override
protected void doClean() throws SQLException {
    for (Table table : allTables()) {
        table.drop();
    }
    List<String> sequenceNames = listObjectNames("SEQUENCE", "IS_GENERATED = false");
    for (String statement : generateDropStatements("SEQUENCE", sequenceNames)) {
        jdbcTemplate.execute(statement);
    }
    List<String> constantNames = listObjectNames("CONSTANT", "");
    for (String statement : generateDropStatements("CONSTANT", constantNames)) {
        jdbcTemplate.execute(statement);
    }
    List<String> aliasNames = jdbcTemplate.queryForStringList("SELECT ALIAS_NAME FROM INFORMATION_SCHEMA.FUNCTION_ALIASES WHERE ALIAS_SCHEMA = ?", name);
    for (String statement : generateDropStatements("ALIAS", aliasNames)) {
        jdbcTemplate.execute(statement);
    }
    List<String> domainNames = listObjectNames("DOMAIN", "");
    if (!domainNames.isEmpty()) {
        if (name.equals(database.getMainConnection().getCurrentSchema().getName())) {
            for (String statement : generateDropStatementsForCurrentSchema("DOMAIN", domainNames)) {
                jdbcTemplate.execute(statement);
            }
        } else {
            LOG.error("Unable to drop DOMAIN objects in schema " + database.quote(name));
        }
    }
}
Also used : Table(org.flywaydb.core.internal.database.base.Table)

Example 10 with Table

use of org.flywaydb.core.internal.database.base.Table in project flyway by flyway.

the class JdbcTableSchemaHistory method removeFailedMigrations.

@Override
public boolean removeFailedMigrations(RepairResult repairResult, MigrationPattern[] migrationPatternFilter) {
    if (!exists()) {
        LOG.info("Repair of failed migration in Schema History table " + table + " not necessary as table doesn't exist.");
        return false;
    }
    List<AppliedMigration> appliedMigrations = filterMigrations(allAppliedMigrations(), migrationPatternFilter);
    boolean failed = appliedMigrations.stream().anyMatch(am -> !am.isSuccess());
    if (!failed) {
        LOG.info("Repair of failed migration in Schema History table " + table + " not necessary. No failed migration detected.");
        return false;
    }
    try {
        appliedMigrations.stream().filter(am -> !am.isSuccess()).forEach(am -> repairResult.migrationsRemoved.add(CommandResultFactory.createRepairOutput(am)));
        for (AppliedMigration appliedMigration : appliedMigrations) {
            jdbcTemplate.execute("DELETE FROM " + table + " WHERE " + database.quote("success") + " = " + database.getBooleanFalse() + " AND " + (appliedMigration.getVersion() != null ? database.quote("version") + " = '" + appliedMigration.getVersion().getVersion() + "'" : database.quote("description") + " = '" + appliedMigration.getDescription() + "'"));
        }
        clearCache();
    } catch (SQLException e) {
        throw new FlywaySqlException("Unable to repair Schema History table " + table, e);
    }
    return true;
}
Also used : Database(org.flywaydb.core.internal.database.base.Database) java.util(java.util) FlywayException(org.flywaydb.core.api.FlywayException) RepairResult(org.flywaydb.core.api.output.RepairResult) RowMapper(org.flywaydb.core.internal.jdbc.RowMapper) CustomLog(lombok.CustomLog) Callable(java.util.concurrent.Callable) MigrationType(org.flywaydb.core.api.MigrationType) MigrationPattern(org.flywaydb.core.api.MigrationPattern) ResolvedMigration(org.flywaydb.core.api.resolver.ResolvedMigration) Connection(org.flywaydb.core.internal.database.base.Connection) ExecutionTemplateFactory(org.flywaydb.core.internal.jdbc.ExecutionTemplateFactory) MigrationVersion(org.flywaydb.core.api.MigrationVersion) CommandResultFactory(org.flywaydb.core.api.output.CommandResultFactory) JdbcNullTypes(org.flywaydb.core.internal.jdbc.JdbcNullTypes) SqlScriptExecutorFactory(org.flywaydb.core.internal.sqlscript.SqlScriptExecutorFactory) SQLException(java.sql.SQLException) JdbcTemplate(org.flywaydb.core.internal.jdbc.JdbcTemplate) SqlScriptFactory(org.flywaydb.core.internal.sqlscript.SqlScriptFactory) ResultSet(java.sql.ResultSet) FlywaySqlException(org.flywaydb.core.internal.exception.FlywaySqlException) RepairOutput(org.flywaydb.core.api.output.RepairOutput) Table(org.flywaydb.core.internal.database.base.Table) ResultSetMetaData(java.sql.ResultSetMetaData) FlywaySqlException(org.flywaydb.core.internal.exception.FlywaySqlException) SQLException(java.sql.SQLException)

Aggregations

Table (org.flywaydb.core.internal.database.base.Table)11 ArrayList (java.util.ArrayList)3 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 java.util (java.util)1 Callable (java.util.concurrent.Callable)1 CustomLog (lombok.CustomLog)1 FlywayException (org.flywaydb.core.api.FlywayException)1 MigrationPattern (org.flywaydb.core.api.MigrationPattern)1 MigrationType (org.flywaydb.core.api.MigrationType)1 MigrationVersion (org.flywaydb.core.api.MigrationVersion)1 CommandResultFactory (org.flywaydb.core.api.output.CommandResultFactory)1 RepairOutput (org.flywaydb.core.api.output.RepairOutput)1 RepairResult (org.flywaydb.core.api.output.RepairResult)1 ResolvedMigration (org.flywaydb.core.api.resolver.ResolvedMigration)1 Connection (org.flywaydb.core.internal.database.base.Connection)1 Database (org.flywaydb.core.internal.database.base.Database)1 FlywaySqlException (org.flywaydb.core.internal.exception.FlywaySqlException)1 ExecutionTemplateFactory (org.flywaydb.core.internal.jdbc.ExecutionTemplateFactory)1