use of com.google.gerrit.reviewdb.client.CurrentSchemaVersion in project gerrit by GerritCodeReview.
the class SchemaUpdater method update.
public void update(final UpdateUI ui) throws OrmException {
try (ReviewDb db = ReviewDbUtil.unwrapDb(schema.open())) {
final SchemaVersion u = updater.get();
final CurrentSchemaVersion version = getSchemaVersion(db);
if (version == null) {
try {
creator.create(db);
} catch (IOException | ConfigInvalidException e) {
throw new OrmException("Cannot initialize schema", e);
}
} else {
try {
u.check(ui, version, db);
} catch (SQLException e) {
throw new OrmException("Cannot upgrade schema", e);
}
updateSystemConfig(db);
}
}
}
use of com.google.gerrit.reviewdb.client.CurrentSchemaVersion in project gerrit by GerritCodeReview.
the class SchemaVersion method migrateData.
private void migrateData(List<SchemaVersion> pending, UpdateUI ui, CurrentSchemaVersion curr, ReviewDb db) throws OrmException, SQLException {
for (SchemaVersion v : pending) {
Stopwatch sw = Stopwatch.createStarted();
ui.message(String.format("Migrating data to schema %d ...", v.getVersionNbr()));
v.migrateData(db, ui);
v.finish(curr, db);
ui.message(String.format("\t> Done (%.3f s)", sw.elapsed(TimeUnit.MILLISECONDS) / 1000d));
}
}
use of com.google.gerrit.reviewdb.client.CurrentSchemaVersion in project gerrit by GerritCodeReview.
the class SchemaVersionCheck method start.
@Override
public void start() {
try (ReviewDb db = schema.open()) {
final CurrentSchemaVersion currentVer = getSchemaVersion(db);
final int expectedVer = SchemaVersion.getBinaryVersion();
if (currentVer == null) {
throw new ProvisionException("Schema not yet initialized." + " Run init to initialize the schema:\n" + "$ java -jar gerrit.war init -d " + site.site_path.toAbsolutePath());
}
if (currentVer.versionNbr < expectedVer) {
throw new ProvisionException("Unsupported schema version " + currentVer.versionNbr + "; expected schema version " + expectedVer + ". Run init to upgrade:\n" + "$ java -jar " + site.gerrit_war.toAbsolutePath() + " init -d " + site.site_path.toAbsolutePath());
} else if (currentVer.versionNbr > expectedVer) {
throw new ProvisionException("Unsupported schema version " + currentVer.versionNbr + "; expected schema version " + expectedVer + ". Downgrade is not supported.");
}
} catch (OrmException e) {
throw new ProvisionException("Cannot read schema_version", e);
}
}
use of com.google.gerrit.reviewdb.client.CurrentSchemaVersion 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.gerrit.reviewdb.client.CurrentSchemaVersion 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