aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration/src/main/java
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2024-12-02 16:12:09 +0100
committersonartech <sonartech@sonarsource.com>2024-12-06 20:03:27 +0000
commit00aef6b15a70f1a1edee729ce69dbc8799165779 (patch)
tree4d25bb3b6c01d9d7655adb5b45e56c83a182814a /server/sonar-db-migration/src/main/java
parent48b3f6a992f1ddfc53c103dd83bbb6019896aa8c (diff)
downloadsonarqube-00aef6b15a70f1a1edee729ce69dbc8799165779.tar.gz
sonarqube-00aef6b15a70f1a1edee729ce69dbc8799165779.zip
SONAR-12647 Remove deprecated complexity metrics
* Remove from complexity measure step * Remove from PersistMeasuresStep * Remove from ScannerMetrics * Add the DB migration * Don't register complexity metrics * Fix tests
Diffstat (limited to 'server/sonar-db-migration/src/main/java')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DbVersion202501.java3
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DeleteRemovedComplexityMeasuresFromProjectMeasures.java61
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DeleteRemovedComplexityMetrics.java46
3 files changed, 109 insertions, 1 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DbVersion202501.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DbVersion202501.java
index aee0eaed57d..6ad62d2f856 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DbVersion202501.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DbVersion202501.java
@@ -33,12 +33,13 @@ public class DbVersion202501 implements DbVersion {
* 2025_01_001
* 2025_01_002
*/
-
@Override
public void addSteps(MigrationStepRegistry registry) {
registry
.add(2025_01_000, "Rename 'sonar.portfolios.confidential.header' property to 'sonar.pdf.confidential.header.enabled'",
MigrateConfidentialHeaderProperty.class)
+ .add(2025_01_001, "Delete removed complexity measures from 'project_measures' table", DeleteRemovedComplexityMeasuresFromProjectMeasures.class)
+ .add(2025_01_002, "Delete removed complexity metrics from 'metrics' table", DeleteRemovedComplexityMetrics.class)
;
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DeleteRemovedComplexityMeasuresFromProjectMeasures.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DeleteRemovedComplexityMeasuresFromProjectMeasures.java
new file mode 100644
index 00000000000..bdbde0b8f01
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DeleteRemovedComplexityMeasuresFromProjectMeasures.java
@@ -0,0 +1,61 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info 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.server.platform.db.migration.version.v202501;
+
+import java.sql.SQLException;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class DeleteRemovedComplexityMeasuresFromProjectMeasures extends DataChange {
+
+ public static final Set<String> COMPLEXITY_METRICS_TO_DELETE = Set.of(
+ "file_complexity",
+ "complexity_in_classes",
+ "class_complexity",
+ "complexity_in_functions",
+ "function_complexity",
+ "function_complexity_distribution",
+ "file_complexity_distribution");
+
+ private static final String SELECT_QUERY = """
+ select pm.uuid from project_measures pm
+ inner join metrics m on pm.metric_uuid = m.uuid
+ where m.name in (%s)
+ """.formatted(COMPLEXITY_METRICS_TO_DELETE.stream().map(s -> "'" + s + "'").collect(Collectors.joining(",")));
+
+ public DeleteRemovedComplexityMeasuresFromProjectMeasures(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select(SELECT_QUERY);
+ massUpdate.update("delete from project_measures where uuid = ?");
+
+ massUpdate.execute((row, update, index) -> {
+ update.setString(1, row.getString(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DeleteRemovedComplexityMetrics.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DeleteRemovedComplexityMetrics.java
new file mode 100644
index 00000000000..ce7e1dc0021
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DeleteRemovedComplexityMetrics.java
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info 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.server.platform.db.migration.version.v202501;
+
+import java.sql.SQLException;
+import java.util.stream.Collectors;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.sonar.server.platform.db.migration.version.v202501.DeleteRemovedComplexityMeasuresFromProjectMeasures.COMPLEXITY_METRICS_TO_DELETE;
+
+public class DeleteRemovedComplexityMetrics extends DataChange {
+
+ private static final String DELETE_QUERY = """
+ delete
+ from metrics
+ where name in (%s)
+ """.formatted(COMPLEXITY_METRICS_TO_DELETE.stream().map(s -> "'" + s + "'").collect(Collectors.joining(",")));
+
+
+ public DeleteRemovedComplexityMetrics(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ context.prepareUpsert(DELETE_QUERY).execute().commit();
+ }
+}