From: Julien Lancelot Date: Mon, 21 Sep 2015 07:33:44 +0000 (+0200) Subject: SONAR-6044 Stop storing distribution of issue-related measures by rule X-Git-Tag: 5.2-RC1~320 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=46445984cf50ef0dda050ea8d369c89936e97f9f;p=sonarqube.git SONAR-6044 Stop storing distribution of issue-related measures by rule --- 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 index 00000000000..f5a91b05286 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/938_remove_rule_measures_on_issues.rb @@ -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 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 : + * + */ +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 @@ + + + + + + + + + + + + + + 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 @@ + + + + + + + + + + + + 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, +);