diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-12-16 09:12:19 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-12-16 14:35:28 +0100 |
commit | 1c34d6ef83b6e9dbfada259c3111acbad3c1ff03 (patch) | |
tree | 1d1c8b9133084a3cb884aada25089436054e22ac /sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java | |
parent | 90d681b83f6399929da48aad426e20f857ff60f3 (diff) | |
download | sonarqube-1c34d6ef83b6e9dbfada259c3111acbad3c1ff03.tar.gz sonarqube-1c34d6ef83b6e9dbfada259c3111acbad3c1ff03.zip |
SONAR-8445 move DatabaseVersion to sonar-db-migration
Diffstat (limited to 'sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java')
-rw-r--r-- | sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java | 155 |
1 files changed, 0 insertions, 155 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java deleted file mode 100644 index 6dcb89683e0..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableSet; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import javax.annotation.Nullable; -import org.sonar.db.DatabaseUtils; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; - -public class DatabaseVersion { - - public static final int LAST_VERSION = 1_502; - - /** - * The minimum supported version which can be upgraded. Lower - * versions must be previously upgraded to LTS version. - * Note that the value can't be less than current LTS version. - */ - public static final int MIN_UPGRADE_VERSION = 1_152; - - /** - * These tables are still involved in DB migrations, so potentially - * incorrect collation must be fixed so that joins with other - * tables are possible. - * - * @see org.sonar.db.charset.ColumnDef#isInSonarQubeTable() - */ - public static final Set<String> OLD_DROPPED_TABLES = ImmutableSet.of( - "active_dashboards", - "activities", - "dashboards", - "issue_filters", - "issue_filter_favourites", - "measure_filters", - "measure_filter_favourites", - "widgets", - "widget_properties"); - - /** - * List of all the tables. - * This list is hardcoded because we didn't succeed in using java.sql.DatabaseMetaData#getTables() in the same way - * for all the supported databases, particularly due to Oracle results. - */ - public static final Set<String> TABLES = ImmutableSet.of( - "active_rules", - "active_rule_parameters", - "authors", - "ce_activity", - "ce_queue", - "ce_task_input", - "ce_scanner_context", - "duplications_index", - "events", - "file_sources", - "groups", - "groups_users", - "group_roles", - "internal_properties", - "issues", - "issue_changes", - "loaded_templates", - "manual_measures", - "metrics", - "notifications", - "organizations", - "permission_templates", - "perm_templates_users", - "perm_templates_groups", - "perm_tpl_characteristics", - "quality_gates", - "quality_gate_conditions", - "projects", - "project_links", - "project_measures", - "project_qprofiles", - "properties", - "qprofile_changes", - "resource_index", - "rules", - "rules_parameters", - "rules_profiles", - "rule_repositories", - "schema_migrations", - "snapshots", - "users", - "user_roles", - "user_tokens", - "webhook_deliveries"); - - private final DbClient dbClient; - - public DatabaseVersion(DbClient dbClient) { - this.dbClient = dbClient; - } - - @VisibleForTesting - static Status getStatus(@Nullable Integer currentVersion, int lastVersion) { - Status status = Status.FRESH_INSTALL; - if (currentVersion != null) { - if (currentVersion == lastVersion) { - status = Status.UP_TO_DATE; - } else if (currentVersion > lastVersion) { - status = Status.REQUIRES_DOWNGRADE; - } else { - status = Status.REQUIRES_UPGRADE; - } - } - return status; - } - - public Status getStatus() { - return getStatus(getVersion(), LAST_VERSION); - } - - public Integer getVersion() { - try (DbSession dbSession = dbClient.openSession(false)) { - if (!DatabaseUtils.tableExists("SCHEMA_MIGRATIONS", dbSession.getConnection())) { - return null; - } - - List<Integer> versions = dbClient.schemaMigrationDao().selectVersions(dbSession); - if (!versions.isEmpty()) { - Collections.sort(versions); - return versions.get(versions.size() - 1); - } - return null; - } - } - - public enum Status { - UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL - } -} |