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);
}
}
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();
}
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);
}
}
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));
}
}
}
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;
}
Aggregations