KEYCLOAK-2737 Handle the databaseSchema: 'validate' against empty database

This commit is contained in:
mposolda 2016-04-05 15:35:37 +02:00
parent 4db73942e6
commit 3d5055d920

View file

@ -114,8 +114,11 @@ public class DefaultMongoUpdaterProvider implements MongoUpdaterProvider {
List<Update> updatesToRun = getUpdatesToRun(executed);
if (!updatesToRun.isEmpty()) {
String errorMessage = String.format("Failed to validate Mongo database schema. Schema needs updating database from %s to %s. Please change databaseSchema to 'update'",
String errorMessage = (executed.isEmpty())
? "Failed to validate Mongo database schema. Database is empty. Please change databaseSchema to 'update'"
: String.format("Failed to validate Mongo database schema. Schema needs updating database from %s to %s. Please change databaseSchema to 'update'",
executed.get(executed.size() - 1), updatesToRun.get(updatesToRun.size() - 1).getId());
throw new RuntimeException(errorMessage);
} else {
log.debug("Validation passed. Database is up to date");