Skip to content

Commit

Permalink
SONAR-6044 Stop storing distribution of issue-related measures by rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Lancelot committed Sep 21, 2015
1 parent 1930d39 commit 4644598
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 4 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@
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;
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 {
Expand Down Expand Up @@ -107,6 +108,8 @@ protected void configureModule() {
RemoveComponentLibraries.class,
RemoveDuplicatedComponentKeys.class,
IncreasePrecisionOfNumerics.class,
RemoveAnalysisReportsFromActivities.class);
RemoveAnalysisReportsFromActivities.class,
RemoveRuleMeasuresOnIssues.class
);
}
}
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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
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");
}

}
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>
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>
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>
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,
);

0 comments on commit 4644598

Please sign in to comment.