diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-09-21 09:33:44 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-09-21 09:33:44 +0200 |
commit | 46445984cf50ef0dda050ea8d369c89936e97f9f (patch) | |
tree | 1614af65877ddba17bad17d8a09ea7f1467cc605 /sonar-db | |
parent | 1930d3927a57af7007c46605ae2a99357218b4ed (diff) | |
download | sonarqube-46445984cf50ef0dda050ea8d369c89936e97f9f.tar.gz sonarqube-46445984cf50ef0dda050ea8d369c89936e97f9f.zip |
SONAR-6044 Stop storing distribution of issue-related measures by rule
Diffstat (limited to 'sonar-db')
10 files changed, 217 insertions, 4 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 index 04df75b3b78..e4af9b19368 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java +++ b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java @@ -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 diff --git a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java index 30179824198..0a28311f2a3 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java +++ b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java @@ -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 index 00000000000..e2c6d6f3f70 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssues.java @@ -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; + } + } + +} diff --git a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql index 5d5904a92d7..320d84ae4f9 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql +++ b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql @@ -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; diff --git a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java index bbb1432b157..e5192fc510a 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java @@ -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 index 00000000000..7e59d20571d --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest.java @@ -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 index 00000000000..120d3fd923b --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute-result.xml @@ -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 index 00000000000..362b25b0a24 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute.xml @@ -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 index 00000000000..6ba6b0e1ae4 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute_nothing.xml @@ -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 index 00000000000..c552eff2c73 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/schema.sql @@ -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, +); |