forked from SonarSource/sonarqube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-6044 Stop storing distribution of issue-related measures by rule
- Loading branch information
Julien Lancelot
committed
Sep 21, 2015
1 parent
1930d39
commit 4644598
Showing
11 changed files
with
248 additions
and
4 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/938_remove_rule_measures_on_issues.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
sonar-db/src/main/java/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssues.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
sonar-db/src/test/java/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute-result.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
38 changes: 38 additions & 0 deletions
38
...db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
12 changes: 12 additions & 0 deletions
12
...est/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/execute_nothing.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
10 changes: 10 additions & 0 deletions
10
...-db/src/test/resources/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest/schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
); |