Fix schema migration that creates index for submodule subscriptions
Commitb0d373c272added 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:
		| @@ -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(); | ||||
|     } | ||||
|   | ||||
| @@ -24,6 +24,8 @@ public interface UpdateUI { | ||||
|  | ||||
|   boolean yesno(boolean def, String msg); | ||||
|  | ||||
|   boolean isBatch(); | ||||
|  | ||||
|   void pruneSchema(StatementExecutor e, List<String> pruneList) | ||||
|       throws OrmException; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Edwin Kempin
					Edwin Kempin