Search in sources :

Example 1 with DialectPostgreSQL

use of com.google.gwtorm.schema.sql.DialectPostgreSQL in project gerrit by GerritCodeReview.

the class Schema_102 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
    JdbcSchema schema = (JdbcSchema) db;
    SqlDialect dialect = schema.getDialect();
    try (StatementExecutor e = newExecutor(db)) {
        // Drop left over indexes that were missed to be removed in schema 84.
        // See "Delete SQL index support" commit for more details:
        // d4ae3a16d5e1464574bd04f429a63eb9c02b3b43
        Pattern pattern = Pattern.compile("^changes_(allOpen|allClosed|byBranchClosed)$", Pattern.CASE_INSENSITIVE);
        String table = "changes";
        Set<String> listIndexes = dialect.listIndexes(schema.getConnection(), table);
        for (String index : listIndexes) {
            if (pattern.matcher(index).matches()) {
                dialect.dropIndex(e, table, index);
            }
        }
        dialect.dropIndex(e, table, "changes_byProjectOpen");
        if (dialect instanceof DialectPostgreSQL) {
            e.execute("CREATE INDEX changes_byProjectOpen" + " ON " + table + " (dest_project_name, last_updated_on)" + " WHERE open = 'Y'");
        } else {
            e.execute("CREATE INDEX changes_byProjectOpen" + " ON " + table + " (open, dest_project_name, last_updated_on)");
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) JdbcSchema(com.google.gwtorm.jdbc.JdbcSchema) DialectPostgreSQL(com.google.gwtorm.schema.sql.DialectPostgreSQL) SqlDialect(com.google.gwtorm.schema.sql.SqlDialect) StatementExecutor(com.google.gwtorm.server.StatementExecutor)

Aggregations

JdbcSchema (com.google.gwtorm.jdbc.JdbcSchema)1 DialectPostgreSQL (com.google.gwtorm.schema.sql.DialectPostgreSQL)1 SqlDialect (com.google.gwtorm.schema.sql.SqlDialect)1 StatementExecutor (com.google.gwtorm.server.StatementExecutor)1 Pattern (java.util.regex.Pattern)1