init: Default database type to JDBC when url is present

If there is no type named in the database section but url is set
force the type to be JDBC. This fixes an upgrade path from 2.1.8 to
2.6 where previously Gerrit assumed JDBC type when url was present
and no type was given.

Bug: issue 1870
Change-Id: I8e30456dd9bb292fc8fc1d9f253413cd676d48ba
This commit is contained in:
Shawn Pearce
2013-04-25 14:07:40 -07:00
parent 6d0c32d0be
commit ad2e9d383a

View File

@@ -16,6 +16,8 @@ package com.google.gerrit.pgm.init;
import static com.google.inject.Stage.PRODUCTION;
import com.google.common.base.Strings;
import com.google.common.collect.Sets;
import com.google.gerrit.pgm.util.ConsoleUI;
import com.google.gerrit.server.config.SitePaths;
import com.google.inject.Binding;
@@ -53,7 +55,7 @@ class InitDatabase implements InitStep {
public void run() {
ui.header("SQL Database");
Set<String> allowedValues = new TreeSet<String>();
Set<String> allowedValues = Sets.newTreeSet();
Injector i = Guice.createInjector(PRODUCTION, new DatabaseConfigModule(site));
List<Binding<DatabaseConfigInitializer>> dbConfigBindings =
i.findBindingsByType(new TypeLiteral<DatabaseConfigInitializer>() {});
@@ -64,6 +66,11 @@ class InitDatabase implements InitStep {
}
}
if (!Strings.isNullOrEmpty(database.get("url"))
&& Strings.isNullOrEmpty(database.get("type"))) {
database.set("type", "jdbc");
}
String dbType =
database.select("Database server type", "type", "h2", allowedValues);