]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6044 Stop storing distribution of issue-related measures by rule 515/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 21 Sep 2015 07:33:44 +0000 (09:33 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 21 Sep 2015 07:33:44 +0000 (09:33 +0200)
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/938_remove_rule_measures_on_issues.rb [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
sonar-db/src/main/java/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssues.java [new file with mode: 0644]
sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java
sonar-db/src/test/java/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest.java [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute_nothing.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/schema.sql [new file with mode: 0644]

diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/938_remove_rule_measures_on_issues.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/938_remove_rule_measures_on_issues.rb
new file mode 100644 (file)
index 0000000..f5a91b0
--- /dev/null
@@ -0,0 +1,31 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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.
+#
+
+#
+# SonarQube 5.2
+# SONAR-6044
+#
+class RemoveRuleMeasuresOnIssues < ActiveRecord::Migration
+
+  def self.up
+    execute_java_migration('org.sonar.db.version.v52.RemoveRuleMeasuresOnIssues')
+  end
+
+end
index 04df75b3b788b2e7e7034b95ba872e42dc3c3227..e4af9b19368c2514211e37e096a18ba9adb6340a 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.db.MyBatis;
 
 public class DatabaseVersion {
 
-  public static final int LAST_VERSION = 937;
+  public static final int LAST_VERSION = 938;
 
   /**
    * The minimum supported version which can be upgraded. Lower
index 30179824198146ec6f8232e564ac654caef9e58a..0a28311f2a327b38e341817bfb906c3c6e0c7663 100644 (file)
@@ -47,7 +47,6 @@ import org.sonar.db.version.v51.RemovePermissionsOnModulesMigrationStep;
 import org.sonar.db.version.v51.RenameComponentRelatedParamsInIssueFilters;
 import org.sonar.db.version.v51.UpdateProjectsModuleUuidPath;
 import org.sonar.db.version.v52.AddManualMeasuresComponentUuidColumn;
-import org.sonar.db.version.v52.RemoveAnalysisReportsFromActivities;
 import org.sonar.db.version.v52.FeedEventsComponentUuid;
 import org.sonar.db.version.v52.FeedFileSourcesDataType;
 import org.sonar.db.version.v52.FeedManualMeasuresComponentUuid;
@@ -55,8 +54,10 @@ import org.sonar.db.version.v52.FeedMetricsBooleans;
 import org.sonar.db.version.v52.FeedProjectLinksComponentUuid;
 import org.sonar.db.version.v52.IncreasePrecisionOfNumerics;
 import org.sonar.db.version.v52.MoveProjectProfileAssociation;
+import org.sonar.db.version.v52.RemoveAnalysisReportsFromActivities;
 import org.sonar.db.version.v52.RemoveComponentLibraries;
 import org.sonar.db.version.v52.RemoveDuplicatedComponentKeys;
+import org.sonar.db.version.v52.RemoveRuleMeasuresOnIssues;
 import org.sonar.db.version.v52.RemoveSnapshotLibraries;
 
 public class MigrationStepModule extends Module {
@@ -107,6 +108,8 @@ public class MigrationStepModule extends Module {
       RemoveComponentLibraries.class,
       RemoveDuplicatedComponentKeys.class,
       IncreasePrecisionOfNumerics.class,
-      RemoveAnalysisReportsFromActivities.class);
+      RemoveAnalysisReportsFromActivities.class,
+      RemoveRuleMeasuresOnIssues.class
+    );
   }
 }
diff --git a/sonar-db/src/main/java/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssues.java b/sonar-db/src/main/java/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssues.java
new file mode 100644 (file)
index 0000000..e2c6d6f
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.v52;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.version.BaseDataChange;
+import org.sonar.db.version.MassUpdate;
+import org.sonar.db.version.Select;
+import org.sonar.db.version.SqlStatement;
+
+/**
+ * Remove all measures linked to a rule related to following metrics :
+ * <ul>
+ *   <li>blocker_violations</li>
+ *   <li>critical_violations</li>
+ *   <li>major_violations</li>
+ *   <li>minor_violations</li>
+ *   <li>info_violations</li>
+ *   <li>new_blocker_violations</li>
+ *   <li>new_critical_violations</li>
+ *   <li>new_major_violations</li>
+ *   <li>new_minor_violations</li>
+ *   <li>new_info_violations</li>
+ *   </ul>
+ */
+public class RemoveRuleMeasuresOnIssues extends BaseDataChange {
+
+  public RemoveRuleMeasuresOnIssues(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    MassUpdate update = context.prepareMassUpdate().rowPluralName("measures");
+    update.select("SELECT p.id FROM project_measures p " +
+      "INNER JOIN metrics m ON m.id=p.metric_id AND m.name IN " +
+      "('blocker_violations', 'critical_violations', 'major_violations', 'minor_violations', 'info_violations', " +
+      "'new_blocker_violations', 'new_critical_violations', 'new_major_violations', 'new_minor_violations', 'new_info_violations') " +
+      "WHERE p.rule_id IS NOT NULL");
+    update.update("DELETE FROM project_measures WHERE id=?");
+    update.execute(MigrationHandler.INSTANCE);
+  }
+
+  private enum MigrationHandler implements MassUpdate.Handler {
+    INSTANCE;
+
+    @Override
+    public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+      update.setLong(1, row.getLong(1));
+      return true;
+    }
+  }
+
+}
index 5d5904a92d74bba149be8303bc9634d4558b13b9..320d84ae4f96589e69fd6688c05d4801bfde637b 100644 (file)
@@ -356,6 +356,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('934');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('935');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('936');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('937');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('938');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index bbb1432b1570991d65aa44b72df8b3358dbe4f01..e5192fc510a19a0c3af4f974ce3bd0bddfc588c3 100644 (file)
@@ -29,6 +29,6 @@ public class MigrationStepModuleTest {
   public void verify_count_of_added_MigrationStep_types() {
     ComponentContainer container = new ComponentContainer();
     new MigrationStepModule().configure(container);
-    assertThat(container.size()).isEqualTo(40);
+    assertThat(container.size()).isEqualTo(41);
   }
 }
diff --git a/sonar-db/src/test/java/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest.java
new file mode 100644 (file)
index 0000000..7e59d20
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.v52;
+
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.db.version.MigrationStep;
+
+public class RemoveRuleMeasuresOnIssuesTest {
+
+  @ClassRule
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, RemoveRuleMeasuresOnIssuesTest.class, "schema.sql");
+
+  MigrationStep migration;
+
+  @Before
+  public void setUp() throws Exception {
+    db.executeUpdateSql("TRUNCATE TABLE metrics");
+    db.executeUpdateSql("TRUNCATE TABLE project_measures");
+    migration = new RemoveRuleMeasuresOnIssues(db.database());
+  }
+
+  @Test
+  public void execute() throws Exception {
+    db.prepareDbUnit(getClass(), "execute.xml");
+
+    migration.execute();
+
+    db.assertDbUnit(getClass(), "execute-result.xml", "project_measures");
+  }
+
+  @Test
+  public void execute_nothing() throws Exception {
+    db.prepareDbUnit(getClass(), "execute_nothing.xml");
+
+    migration.execute();
+
+    db.assertDbUnit(getClass(), "execute_nothing.xml", "project_measures");
+  }
+
+}
diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute-result.xml b/sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute-result.xml
new file mode 100644 (file)
index 0000000..120d3fd
--- /dev/null
@@ -0,0 +1,14 @@
+<dataset>
+
+  <project_measures id="11" metric_id="1" rule_id="[null]"/>
+  <project_measures id="12" metric_id="2" rule_id="[null]"/>
+  <project_measures id="13" metric_id="3" rule_id="[null]"/>
+  <project_measures id="14" metric_id="4" rule_id="[null]"/>
+  <project_measures id="15" metric_id="5" rule_id="[null]"/>
+  <project_measures id="16" metric_id="6" rule_id="[null]"/>
+  <project_measures id="17" metric_id="7" rule_id="[null]"/>
+  <project_measures id="18" metric_id="8" rule_id="[null]"/>
+  <project_measures id="19" metric_id="9" rule_id="[null]"/>
+  <project_measures id="20" metric_id="10" rule_id="[null]"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute.xml b/sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute.xml
new file mode 100644 (file)
index 0000000..362b25b
--- /dev/null
@@ -0,0 +1,38 @@
+<dataset>
+
+  <metrics id="1" name="blocker_violations"/>
+  <metrics id="2" name="critical_violations"/>
+  <metrics id="3" name="major_violations"/>
+  <metrics id="4" name="minor_violations"/>
+  <metrics id="5" name="info_violations"/>
+  <metrics id="6" name="new_blocker_violations"/>
+  <metrics id="7" name="new_critical_violations"/>
+  <metrics id="8" name="new_major_violations"/>
+  <metrics id="9" name="new_minor_violations"/>
+  <metrics id="10" name="new_info_violations"/>
+
+  <!-- Should be removed -->
+  <project_measures id="1" metric_id="1" rule_id="1"/>
+  <project_measures id="2" metric_id="2" rule_id="1"/>
+  <project_measures id="3" metric_id="3" rule_id="1"/>
+  <project_measures id="4" metric_id="4" rule_id="1"/>
+  <project_measures id="5" metric_id="5" rule_id="1"/>
+  <project_measures id="6" metric_id="6" rule_id="1"/>
+  <project_measures id="7" metric_id="7" rule_id="1"/>
+  <project_measures id="8" metric_id="8" rule_id="1"/>
+  <project_measures id="9" metric_id="9" rule_id="1"/>
+  <project_measures id="10" metric_id="10" rule_id="1"/>
+
+  <!-- Should not be removed -->
+  <project_measures id="11" metric_id="1"/>
+  <project_measures id="12" metric_id="2"/>
+  <project_measures id="13" metric_id="3"/>
+  <project_measures id="14" metric_id="4"/>
+  <project_measures id="15" metric_id="5"/>
+  <project_measures id="16" metric_id="6"/>
+  <project_measures id="17" metric_id="7"/>
+  <project_measures id="18" metric_id="8"/>
+  <project_measures id="19" metric_id="9"/>
+  <project_measures id="20" metric_id="10"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute_nothing.xml b/sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute_nothing.xml
new file mode 100644 (file)
index 0000000..6ba6b0e
--- /dev/null
@@ -0,0 +1,12 @@
+<dataset>
+
+  <!-- These measures should not be removed -->
+
+  <metrics id="1" name="violations"/>
+  <metrics id="2" name="new_violations"/>
+
+  <project_measures id="1" metric_id="1" rule_id="[null]"/>
+  <project_measures id="2" metric_id="2" rule_id="[null]"/>
+
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/schema.sql
new file mode 100644 (file)
index 0000000..c552eff
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "PROJECT_MEASURES" (
+  "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "METRIC_ID" INTEGER NOT NULL,
+  "RULE_ID" INTEGER,
+);
+
+CREATE TABLE "METRICS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "NAME" VARCHAR(64) NOT NULL,
+);