Fix upgrading H2 from schema 20 to current
We can't drop the unused objects out because H2 requires us to first drop the constraints that apply to these columns. Change-Id: I02313f1c4a4180bcd0cce24a15bdffe817606987 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import com.google.gerrit.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.reviewdb.SystemConfig;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.jdbc.JdbcSchema;
|
||||
import com.google.gwtorm.schema.sql.DialectH2;
|
||||
import com.google.gwtorm.schema.sql.DialectMySQL;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
@@ -55,6 +56,10 @@ class Schema_21 extends SchemaVersion {
|
||||
|
||||
if (jdbc.getDialect() instanceof DialectMySQL) {
|
||||
s.execute("DROP FUNCTION nextval_project_id");
|
||||
|
||||
} else if (jdbc.getDialect() instanceof DialectH2) {
|
||||
s.execute("ALTER TABLE projects DROP CONSTRAINT"
|
||||
+ " IF EXISTS CONSTRAINT_F3");
|
||||
}
|
||||
} finally {
|
||||
s.close();
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.google.gerrit.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.reviewdb.AccountExternalId.Key;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.jdbc.JdbcSchema;
|
||||
import com.google.gwtorm.schema.sql.DialectH2;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
@@ -39,15 +40,15 @@ class Schema_22 extends SchemaVersion {
|
||||
|
||||
@Override
|
||||
protected void migrateData(ReviewDb db) throws OrmException, SQLException {
|
||||
Collection<AccountExternalId> ids = new ArrayList<AccountExternalId>();
|
||||
Statement queryStmt = ((JdbcSchema) db).getConnection().createStatement();
|
||||
Statement s = ((JdbcSchema) db).getConnection().createStatement();
|
||||
try {
|
||||
ResultSet results =
|
||||
queryStmt.executeQuery(//
|
||||
s.executeQuery(//
|
||||
"SELECT account_id, ssh_user_name"
|
||||
+ " FROM accounts" //
|
||||
+ " WHERE ssh_user_name IS NOT NULL"
|
||||
+ " AND ssh_user_name <> ''");
|
||||
Collection<AccountExternalId> ids = new ArrayList<AccountExternalId>();
|
||||
while (results.next()) {
|
||||
final int accountId = results.getInt(1);
|
||||
final String userName = results.getString(2);
|
||||
@@ -56,10 +57,15 @@ class Schema_22 extends SchemaVersion {
|
||||
final AccountExternalId.Key key = toKey(userName);
|
||||
ids.add(new AccountExternalId(account, key));
|
||||
}
|
||||
} finally {
|
||||
queryStmt.close();
|
||||
}
|
||||
db.accountExternalIds().insert(ids);
|
||||
|
||||
if (((JdbcSchema) db).getDialect() instanceof DialectH2) {
|
||||
s.execute("ALTER TABLE accounts DROP CONSTRAINT"
|
||||
+ " IF EXISTS CONSTRAINT_AF");
|
||||
}
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
private Key toKey(final String userName) {
|
||||
|
||||
Reference in New Issue
Block a user