Fix mongo migration

This commit is contained in:
mposolda 2015-04-28 11:10:48 +02:00
parent 8224f3ba48
commit d4c69e98ce

View file

@ -23,13 +23,15 @@ public class Update1_2_0_RC1 extends Update {
convertApplicationsToClients(); convertApplicationsToClients();
convertOAuthClientsToClients(); convertOAuthClientsToClients();
db.getCollection("realms").update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("adminAppId", "clientId")), false, true); db.getCollection("realms").update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("adminAppId", "masterAdminClient")), false, true);
ensureIndex("userConsents", new String[]{"clientId", "userId"}, true, false); ensureIndex("userConsents", new String[]{"clientId", "userId"}, true, false);
} }
private void convertApplicationsToClients() { private void convertApplicationsToClients() {
DBCollection applications = db.getCollection("applications"); DBCollection applications = db.getCollection("applications");
applications.dropIndex("realmId_1_name_1");
applications.update(new BasicDBObject(), new BasicDBObject("$set", new BasicDBObject("consentRequired", false)), false, true); applications.update(new BasicDBObject(), new BasicDBObject("$set", new BasicDBObject("consentRequired", false)), false, true);
applications.update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("name", "clientId")), false, true); applications.update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("name", "clientId")), false, true);
renameCollection("applications", "clients"); renameCollection("applications", "clients");
@ -39,14 +41,14 @@ public class Update1_2_0_RC1 extends Update {
roles.update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("applicationId", "clientId")), false, true); roles.update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("applicationId", "clientId")), false, true);
log.debugv("Renamed roles.applicationId to roles.clientId"); log.debugv("Renamed roles.applicationId to roles.clientId");
db.getCollection("clients").dropIndex("realmId_1_name_1");
ensureIndex("clients", new String[]{"realmId", "clientId"}, true, false); ensureIndex("clients", new String[]{"realmId", "clientId"}, true, false);
} }
private void convertOAuthClientsToClients() { private void convertOAuthClientsToClients() {
DBCollection clients = db.getCollection("clients"); DBCollection clients = db.getCollection("clients");
DBCollection oauthClients = db.getCollection("oauthClients"); DBCollection oauthClients = db.getCollection("oauthClients");
oauthClients.dropIndex("realmId_1_name_1");
oauthClients.update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("name", "clientId")), false, true); oauthClients.update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("name", "clientId")), false, true);
oauthClients.update(new BasicDBObject(), new BasicDBObject("$set", new BasicDBObject("consentRequired", true)), false, true); oauthClients.update(new BasicDBObject(), new BasicDBObject("$set", new BasicDBObject("consentRequired", true)), false, true);