Fix schema migration that creates index for submodule subscriptions

Commit b0d373c272 added a schema
migration that creates an index for submodule subscriptions.
This migration fails if the index already exists. This can be if the
site was newly created after the submodule subscription feature
(d15704079c) was introduced or if the
missing index was created manually.

This change fixes the migration by catching any SQLException when
trying to create the index and asking the user whether this exception
should be ignored. An automatic decision is not possible since specific
SQL error codes for this case are not available for all supported
databases.

Change-Id: I7ecb3f0ed050f22753d268dcac01ca3bdb2d84b3
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2012-05-25 14:00:11 +02:00
parent f87fe87c16
commit 5e43e77ab5
4 changed files with 30 additions and 0 deletions

View File

@@ -35,6 +35,24 @@ public class Schema_68 extends SchemaVersion {
try {
stmt.execute("CREATE INDEX submodule_subscription_access_bySubscription"
+ " ON submodule_subscriptions (submodule_project_name, submodule_branch_name)");
} catch (SQLException e) {
// the index creation might have failed because the index exists already,
// in this case the exception can be safely ignored,
// but there are also other possible reasons for an exception here that
// should not be ignored,
// -> ask the user whether to ignore this exception or not
ui.message("warning: Cannot create index for submodule subscriptions");
ui.message(e.getMessage());
if (ui.isBatch()) {
ui.message("you may ignore this warning when running in interactive mode");
throw e;
} else {
final boolean answer = ui.yesno(false, "Ignore warning and proceed with schema upgrade");
if (!answer) {
throw e;
}
}
} finally {
stmt.close();
}

View File

@@ -24,6 +24,8 @@ public interface UpdateUI {
boolean yesno(boolean def, String msg);
boolean isBatch();
void pruneSchema(StatementExecutor e, List<String> pruneList)
throws OrmException;
}