Implement automatic schema upgrading
SchemaVersion subclasses form a DAG, managed by Guice, chaining the current schema version to its immediate predecessor. When a version is selected, we try to upgrade to it by first asking is predecessor to validate (and upgrade). Drops of schema elements are not performed automatically, but instead are printed to the console so the administrator can verify the drops aren't their own private schema elements, and execute the commands they know won't damage their own private data. Change-Id: I2a53749ca23432da2a9b1866203aafb151b48aab Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -34,8 +34,10 @@ import com.google.gerrit.server.git.GitProjectImporter;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.LocalDiskRepositoryManager;
|
||||
import com.google.gerrit.server.schema.SchemaUpdater;
|
||||
import com.google.gerrit.server.schema.UpdateUI;
|
||||
import com.google.gerrit.server.util.HostPlatform;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.StatementExecutor;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.CreationException;
|
||||
import com.google.inject.Guice;
|
||||
@@ -76,7 +78,7 @@ public class Init extends SiteProgram {
|
||||
init.flags.deleteOnFailure = false;
|
||||
|
||||
run = createSiteRun(init);
|
||||
run.schemaUpdater.update();
|
||||
run.upgradeSchema();
|
||||
run.importGit();
|
||||
} catch (Exception failure) {
|
||||
if (init.flags.deleteOnFailure) {
|
||||
@@ -176,6 +178,39 @@ public class Init extends SiteProgram {
|
||||
this.browser = browser;
|
||||
}
|
||||
|
||||
void upgradeSchema() throws OrmException {
|
||||
schemaUpdater.update(new UpdateUI() {
|
||||
@Override
|
||||
public void message(String msg) {
|
||||
System.err.println(msg);
|
||||
System.err.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pruneSchema(StatementExecutor e, List<String> pruneList)
|
||||
throws OrmException {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Execute the following SQL to drop unused objects:\n");
|
||||
msg.append("\n");
|
||||
for (String sql : pruneList) {
|
||||
msg.append(" ");
|
||||
msg.append(sql);
|
||||
msg.append(";\n");
|
||||
}
|
||||
|
||||
if (ui.isBatch()) {
|
||||
System.err.print(msg);
|
||||
System.err.flush();
|
||||
|
||||
} else if (ui.yesno(true, "%s\nExecute now", msg)) {
|
||||
for (String sql : pruneList) {
|
||||
e.execute(sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void importGit() throws OrmException, IOException {
|
||||
if (flags.importProjects) {
|
||||
gitProjectImporter.run(new GitProjectImporter.Messages() {
|
||||
|
@@ -18,10 +18,10 @@ import static com.google.inject.Scopes.SINGLETON;
|
||||
import static com.google.inject.Stage.PRODUCTION;
|
||||
|
||||
import com.google.gerrit.lifecycle.LifecycleModule;
|
||||
import com.google.gerrit.server.config.DatabaseModule;
|
||||
import com.google.gerrit.server.config.GerritServerConfigModule;
|
||||
import com.google.gerrit.server.config.SitePath;
|
||||
import com.google.gerrit.server.schema.DataSourceProvider;
|
||||
import com.google.gerrit.server.schema.DatabaseModule;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.CreationException;
|
||||
|
Reference in New Issue
Block a user