Search in sources :

Example 1 with Table

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

the class DB2Schema method generateDropVersioningStatement.

/**
 * @return All tables that have versioning associated with them.
 */
private List<String> generateDropVersioningStatement() throws SQLException {
    List<String> dropVersioningStatements = new ArrayList<>();
    Table[] versioningTables = findTables("select TABNAME from SYSCAT.TABLES where TEMPORALTYPE <> 'N' and TABSCHEMA = ?", name);
    for (Table table : versioningTables) {
        dropVersioningStatements.add("ALTER TABLE " + table.toString() + " DROP VERSIONING");
    }
    return dropVersioningStatements;
}
Also used : Table(org.flywaydb.core.internal.database.base.Table) ArrayList(java.util.ArrayList)

Example 2 with Table

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

the class DerbySchema method doClean.

@Override
protected void doClean() throws SQLException {
    List<String> triggerNames = listObjectNames("TRIGGER", "");
    for (String statement : generateDropStatements("TRIGGER", triggerNames, "")) {
        jdbcTemplate.execute(statement);
    }
    for (String statement : generateDropStatementsForConstraints()) {
        jdbcTemplate.execute(statement);
    }
    List<String> viewNames = listObjectNames("TABLE", "TABLETYPE='V'");
    for (String statement : generateDropStatements("VIEW", viewNames, "")) {
        jdbcTemplate.execute(statement);
    }
    for (Table table : allTables()) {
        table.drop();
    }
    List<String> sequenceNames = listObjectNames("SEQUENCE", "");
    for (String statement : generateDropStatements("SEQUENCE", sequenceNames, "RESTRICT")) {
        jdbcTemplate.execute(statement);
    }
}
Also used : Table(org.flywaydb.core.internal.database.base.Table)

Example 3 with Table

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

the class SQLiteSchema method doClean.

@Override
protected void doClean() throws SQLException {
    foreignKeysEnabled = jdbcTemplate.queryForBoolean("PRAGMA foreign_keys");
    List<String> viewNames = jdbcTemplate.queryForStringList("SELECT tbl_name FROM " + database.quote(name) + ".sqlite_master WHERE type='view'");
    for (String viewName : viewNames) {
        jdbcTemplate.execute("DROP VIEW " + database.quote(name, viewName));
    }
    for (Table table : allTables()) {
        table.drop();
    }
    if (getTable(SQLiteTable.SQLITE_SEQUENCE).exists()) {
        jdbcTemplate.execute("DELETE FROM " + SQLiteTable.SQLITE_SEQUENCE);
    }
}
Also used : Table(org.flywaydb.core.internal.database.base.Table)

Example 4 with Table

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

the class MySQLSchema method doClean.

@Override
protected void doClean() throws SQLException {
    if (database.eventSchedulerQueryable) {
        for (String statement : cleanEvents()) {
            jdbcTemplate.execute(statement);
        }
    }
    for (String statement : cleanRoutines()) {
        jdbcTemplate.execute(statement);
    }
    for (String statement : cleanViews()) {
        jdbcTemplate.execute(statement);
    }
    jdbcTemplate.execute("SET FOREIGN_KEY_CHECKS = 0");
    for (Table table : allTables()) {
        table.drop();
    }
    jdbcTemplate.execute("SET FOREIGN_KEY_CHECKS = 1");
    // MariaDB 10.3 and newer only
    for (String statement : cleanSequences()) {
        jdbcTemplate.execute(statement);
    }
}
Also used : Table(org.flywaydb.core.internal.database.base.Table)

Example 5 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)

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