2016-02-03 10:20:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
|
|
|
* and other contributors as indicated by the @author tags.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
package org.keycloak.migration;
|
|
|
|
|
|
|
|
import org.jboss.logging.Logger;
|
2016-11-23 21:48:02 +00:00
|
|
|
import org.keycloak.migration.migrators.MigrateTo1_2_0;
|
|
|
|
import org.keycloak.migration.migrators.MigrateTo1_3_0;
|
|
|
|
import org.keycloak.migration.migrators.MigrateTo1_4_0;
|
|
|
|
import org.keycloak.migration.migrators.MigrateTo1_5_0;
|
|
|
|
import org.keycloak.migration.migrators.MigrateTo1_6_0;
|
|
|
|
import org.keycloak.migration.migrators.MigrateTo1_7_0;
|
|
|
|
import org.keycloak.migration.migrators.MigrateTo1_8_0;
|
2016-02-18 15:47:26 +00:00
|
|
|
import org.keycloak.migration.migrators.MigrateTo1_9_0;
|
2016-03-11 14:25:21 +00:00
|
|
|
import org.keycloak.migration.migrators.MigrateTo1_9_2;
|
2016-06-29 15:07:49 +00:00
|
|
|
import org.keycloak.migration.migrators.MigrateTo2_0_0;
|
2016-07-05 19:06:46 +00:00
|
|
|
import org.keycloak.migration.migrators.MigrateTo2_1_0;
|
2016-09-07 06:52:55 +00:00
|
|
|
import org.keycloak.migration.migrators.MigrateTo2_2_0;
|
2016-10-18 10:43:39 +00:00
|
|
|
import org.keycloak.migration.migrators.MigrateTo2_3_0;
|
2016-12-15 10:46:15 +00:00
|
|
|
import org.keycloak.migration.migrators.MigrateTo2_5_0;
|
2016-09-07 06:52:55 +00:00
|
|
|
import org.keycloak.migration.migrators.Migration;
|
2015-07-17 11:45:43 +00:00
|
|
|
import org.keycloak.models.KeycloakSession;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
|
|
|
* @version $Revision: 1 $
|
|
|
|
*/
|
|
|
|
public class MigrationModelManager {
|
|
|
|
private static Logger logger = Logger.getLogger(MigrationModelManager.class);
|
|
|
|
|
2016-09-07 06:52:55 +00:00
|
|
|
private static final Migration[] migrations = {
|
2016-11-23 21:48:02 +00:00
|
|
|
new MigrateTo1_2_0(),
|
|
|
|
new MigrateTo1_3_0(),
|
|
|
|
new MigrateTo1_4_0(),
|
|
|
|
new MigrateTo1_5_0(),
|
|
|
|
new MigrateTo1_6_0(),
|
|
|
|
new MigrateTo1_7_0(),
|
|
|
|
new MigrateTo1_8_0(),
|
|
|
|
new MigrateTo1_9_0(),
|
2016-09-07 06:52:55 +00:00
|
|
|
new MigrateTo1_9_2(),
|
|
|
|
new MigrateTo2_0_0(),
|
|
|
|
new MigrateTo2_1_0(),
|
|
|
|
new MigrateTo2_2_0(),
|
2016-10-18 10:43:39 +00:00
|
|
|
new MigrateTo2_3_0(),
|
2016-12-15 10:46:15 +00:00
|
|
|
new MigrateTo2_5_0(),
|
2016-09-07 06:52:55 +00:00
|
|
|
};
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
public static void migrate(KeycloakSession session) {
|
2016-09-07 06:52:55 +00:00
|
|
|
ModelVersion latest = migrations[migrations.length-1].getVersion();
|
2015-07-17 11:45:43 +00:00
|
|
|
MigrationModel model = session.realms().getMigrationModel();
|
|
|
|
ModelVersion stored = null;
|
2016-09-07 06:52:55 +00:00
|
|
|
if (model.getStoredVersion() != null) {
|
|
|
|
stored = new ModelVersion(model.getStoredVersion());
|
|
|
|
if (latest.equals(stored)) {
|
|
|
|
return;
|
2015-09-23 10:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 06:52:55 +00:00
|
|
|
|
|
|
|
for (Migration m : migrations) {
|
|
|
|
if (stored == null || stored.lessThan(m.getVersion())) {
|
|
|
|
if (stored != null) {
|
|
|
|
logger.debugf("Migrating older model to %s", m.getVersion());
|
|
|
|
}
|
|
|
|
m.migrate(session);
|
2016-07-05 19:06:46 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
|
2016-09-07 06:52:55 +00:00
|
|
|
model.setStoredVersion(latest.toString());
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
}
|