use of com.google.gwtorm.jdbc.JdbcSchema in project gerrit by GerritCodeReview.
the class SchemaVersion method updateSchema.
private void updateSchema(List<SchemaVersion> pending, UpdateUI ui, ReviewDb db) throws OrmException, SQLException {
for (SchemaVersion v : pending) {
ui.message(String.format("Upgrading schema to %d ...", v.getVersionNbr()));
v.preUpdateSchema(db);
}
JdbcSchema s = (JdbcSchema) db;
try (JdbcExecutor e = new JdbcExecutor(s)) {
s.updateSchema(e);
}
}
use of com.google.gwtorm.jdbc.JdbcSchema 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)");
}
}
}
use of com.google.gwtorm.jdbc.JdbcSchema in project gerrit by GerritCodeReview.
the class Schema_105 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws SQLException, OrmException {
JdbcSchema schema = (JdbcSchema) db;
SqlDialect dialect = schema.getDialect();
Map<String, OrmException> errors = new HashMap<>();
try (StatementExecutor e = newExecutor(db)) {
for (String index : listChangesIndexes(schema)) {
ui.message("Dropping index " + index + " on table " + TABLE);
try {
dialect.dropIndex(e, TABLE, index);
} catch (OrmException err) {
errors.put(index, err);
}
}
}
for (String index : listChangesIndexes(schema)) {
String msg = "Failed to drop index " + index;
OrmException err = errors.get(index);
if (err != null) {
msg += ": " + err.getMessage();
}
ui.message(msg);
}
}
use of com.google.gwtorm.jdbc.JdbcSchema in project gerrit by GerritCodeReview.
the class SchemaCreator method create.
public void create(final ReviewDb db) throws OrmException, IOException, ConfigInvalidException {
final JdbcSchema jdbc = (JdbcSchema) db;
try (JdbcExecutor e = new JdbcExecutor(jdbc)) {
jdbc.updateSchema(e);
}
final CurrentSchemaVersion sVer = CurrentSchemaVersion.create();
sVer.versionNbr = SchemaVersion.getBinaryVersion();
db.schemaVersion().insert(Collections.singleton(sVer));
createDefaultGroups(db);
initSystemConfig(db);
allProjectsCreator.setAdministrators(GroupReference.forGroup(admin)).setBatchUsers(GroupReference.forGroup(batch)).create();
allUsersCreator.setAdministrators(GroupReference.forGroup(admin)).create();
dataSourceType.getIndexScript().run(db);
}
use of com.google.gwtorm.jdbc.JdbcSchema in project gerrit by GerritCodeReview.
the class SchemaVersion method upgradeFrom.
/** Runs check on the prior schema version, and then upgrades. */
private void upgradeFrom(UpdateUI ui, CurrentSchemaVersion curr, ReviewDb db) throws OrmException, SQLException {
List<SchemaVersion> pending = pending(curr.versionNbr);
updateSchema(pending, ui, db);
migrateData(pending, ui, curr, db);
JdbcSchema s = (JdbcSchema) db;
final List<String> pruneList = new ArrayList<>();
s.pruneSchema(new StatementExecutor() {
@Override
public void execute(String sql) {
pruneList.add(sql);
}
@Override
public void close() {
// Do nothing.
}
});
try (JdbcExecutor e = new JdbcExecutor(s)) {
if (!pruneList.isEmpty()) {
ui.pruneSchema(e, pruneList);
}
}
}
Aggregations