From 450f1eb2189848ff292c6286db4186d7ffd487ec Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 1 Mar 2016 10:04:51 +0100 Subject: [PATCH] SONAR-7330 remove column RULES.CHARACTERISTIC_ID and DEFAULT_CHARACTERISTIC_ID --- .../startup/ClearRulesOverloadedDebt.java | 3 +- .../startup/ClearRulesOverloadedDebtTest.java | 19 +++++------- .../insert_new_issue.xml | 1 - .../step/PersistIssuesStepTest/shared.xml | 1 - .../BackendCleanupMediumTest/shared.xml | 1 - .../insert_new_rules-result.xml | 3 -- ..._disable_already_disabled_rules-result.xml | 4 --- .../not_disable_already_disabled_rules.xml | 2 -- ...c_when_characteristic_not_found-result.xml | 2 -- ...teristic_when_characteristic_not_found.xml | 1 - ...rriding_characteristic_disabled-result.xml | 2 -- ...and_overriding_characteristic_disabled.xml | 2 -- ...racteristic_has_been_overridden-result.xml | 2 -- ...but_characteristic_has_been_overridden.xml | 2 -- .../update_rule_fields-result.xml | 2 -- .../RegisterRulesTest/update_rule_fields.xml | 1 - .../update_template_rule_language-result.xml | 4 --- .../update_template_rule_language.xml | 4 --- ...8_drop_rules_dates_and_characteristics.rb} | 4 +-- .../main/java/org/sonar/db/rule/RuleDto.java | 31 ------------------- .../java/org/sonar/db/rule/RuleMapper.java | 2 -- .../db/version/v55/DropRulesDateColumns.java | 2 +- .../org/sonar/db/rule/RuleMapper.xml | 16 ++-------- .../org/sonar/db/version/schema-h2.ddl | 2 -- .../version/v55/DropRulesDateColumnsTest.java | 2 +- .../RuleDaoTest/insert_parameter-result.xml | 1 - .../db/rule/RuleDaoTest/insert_parameter.xml | 1 - .../RuleDaoTest/selectEnabledAndNonManual.xml | 3 -- .../version/v51/FeedIssueTagsTest/before.xml | 4 --- 29 files changed, 15 insertions(+), 109 deletions(-) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1108_drop_rules_date_columns.rb => 1108_drop_rules_dates_and_characteristics.rb} (91%) diff --git a/server/sonar-server/src/main/java/org/sonar/server/startup/ClearRulesOverloadedDebt.java b/server/sonar-server/src/main/java/org/sonar/server/startup/ClearRulesOverloadedDebt.java index ea1913020e6..87e9e944d5c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/startup/ClearRulesOverloadedDebt.java +++ b/server/sonar-server/src/main/java/org/sonar/server/startup/ClearRulesOverloadedDebt.java @@ -81,7 +81,6 @@ public class ClearRulesOverloadedDebt implements Startable { int countClearedRules = 0; for (RuleDto rule : dbClient.ruleDao().selectAll(session)) { if (isDebtOverridden(rule)) { - rule.setSubCharacteristicId(null); rule.setRemediationFunction(null); rule.setRemediationCoefficient(null); rule.setRemediationOffset(null); @@ -97,7 +96,7 @@ public class ClearRulesOverloadedDebt implements Startable { } private static boolean isDebtOverridden(RuleDto ruleDto) { - return ruleDto.getSubCharacteristicId() != null || ruleDto.getRemediationFunction() != null || ruleDto.getRemediationCoefficient() != null + return ruleDto.getRemediationFunction() != null || ruleDto.getRemediationCoefficient() != null || ruleDto.getRemediationOffset() != null; } diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java index f6bc97fef8f..ffb53b62375 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java @@ -45,8 +45,6 @@ import static org.sonar.db.loadedtemplate.LoadedTemplateDto.ONE_SHOT_TASK_TYPE; public class ClearRulesOverloadedDebtTest { - static final int SUB_CHARACTERISTIC_ID = 1; - private static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1; private static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2; private static final RuleKey RULE_KEY_3 = RuleTesting.XOO_X3; @@ -72,11 +70,11 @@ public class ClearRulesOverloadedDebtTest { @Test public void remove_overridden_debt() throws Exception { // Characteristic and remediation function is overridden - insertRuleDto(RULE_KEY_1, SUB_CHARACTERISTIC_ID, "LINEAR", null, "1d"); + insertRuleDto(RULE_KEY_1, "LINEAR", null, "1d"); // Only characteristic is overridden - insertRuleDto(RULE_KEY_2, SUB_CHARACTERISTIC_ID, null, null, null); + insertRuleDto(RULE_KEY_2, null, null, null); // Only remediation function is overridden - insertRuleDto(RULE_KEY_3, null, "CONSTANT_ISSUE", "5min", null); + insertRuleDto(RULE_KEY_3, "CONSTANT_ISSUE", "5min", null); underTest.start(); @@ -89,7 +87,7 @@ public class ClearRulesOverloadedDebtTest { @Test public void not_update_rule_debt_not_overridden() throws Exception { - RuleDto rule = insertRuleDto(RULE_KEY_1, null, null, null, null); + RuleDto rule = insertRuleDto(RULE_KEY_1, null, null, null); long updateAt = rule.getUpdatedAt(); underTest.start(); @@ -105,7 +103,7 @@ public class ClearRulesOverloadedDebtTest { @Test public void not_update_rule_debt_when_sqale_is_installed() throws Exception { insertSqaleProperty(); - RuleDto rule = insertRuleDto(RULE_KEY_1, SUB_CHARACTERISTIC_ID, "LINEAR", null, "1d"); + RuleDto rule = insertRuleDto(RULE_KEY_1, "LINEAR", null, "1d"); long updateAt = rule.getUpdatedAt(); underTest.start(); @@ -119,7 +117,7 @@ public class ClearRulesOverloadedDebtTest { @Test public void not_execute_task_when_already_executed() throws Exception { - insertRuleDto(RULE_KEY_1, SUB_CHARACTERISTIC_ID, "LINEAR", null, "1d"); + insertRuleDto(RULE_KEY_1, "LINEAR", null, "1d"); underTest.start(); verifyLog(); verifyTaskRegistered(); @@ -135,14 +133,13 @@ public class ClearRulesOverloadedDebtTest { dbSession.commit(true); RuleDto ruleDto = ruleDao.selectOrFailByKey(dbSession, ruleKey); - assertThat(ruleDto.getSubCharacteristicId()).isNull(); assertThat(ruleDto.getRemediationFunction()).isNull(); assertThat(ruleDto.getRemediationCoefficient()).isNull(); assertThat(ruleDto.getRemediationOffset()).isNull(); } - private RuleDto insertRuleDto(RuleKey ruleKey, @Nullable Integer subCharId, @Nullable String function, @Nullable String coeff, @Nullable String offset) { - RuleDto ruleDto = RuleTesting.newDto(ruleKey).setSubCharacteristicId(subCharId).setRemediationFunction(function).setRemediationOffset(offset).setRemediationCoefficient(coeff); + private RuleDto insertRuleDto(RuleKey ruleKey, @Nullable String function, @Nullable String coeff, @Nullable String offset) { + RuleDto ruleDto = RuleTesting.newDto(ruleKey).setRemediationFunction(function).setRemediationOffset(offset).setRemediationCoefficient(coeff); ruleDao.insert(dbSession, ruleDto ); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistIssuesStepTest/insert_new_issue.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistIssuesStepTest/insert_new_issue.xml index b3228c223b1..a149ee15618 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistIssuesStepTest/insert_new_issue.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistIssuesStepTest/insert_new_issue.xml @@ -3,7 +3,6 @@ selectNonManual(); - List selectBySubCharacteristicId(int characteristicId); - RuleDto selectById(long id); List selectByIds(@Param("ids") List ids); diff --git a/sonar-db/src/main/java/org/sonar/db/version/v55/DropRulesDateColumns.java b/sonar-db/src/main/java/org/sonar/db/version/v55/DropRulesDateColumns.java index 38f440cda5b..082f44d6806 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v55/DropRulesDateColumns.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v55/DropRulesDateColumns.java @@ -47,7 +47,7 @@ public class DropRulesDateColumns extends DdlChange { @VisibleForTesting String generateSql() { return new DropColumnsBuilder(db.getDialect(), "rules", - "created_at", "updated_at") + "created_at", "updated_at", "characteristic_id", "default_characteristic_id") .build(); } diff --git a/sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml b/sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml index 3492b3e79ff..aded450d199 100644 --- a/sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml @@ -20,8 +20,6 @@ r.note_user_login as "noteUserLogin", r.note_created_at as "noteCreatedAt", r.note_updated_at as "noteUpdatedAt", - r.characteristic_id as "subCharacteristicId", - r.default_characteristic_id as "defaultSubCharacteristicId", r.remediation_function as "remediationFunction", r.default_remediation_function as "defaultRemediationFunction", r.remediation_coeff as "remediationCoefficient", @@ -104,13 +102,6 @@ where r.plugin_name != 'manual' - -