From: Guillaume Jambet Date: Tue, 10 Apr 2018 07:33:09 +0000 (+0200) Subject: SONAR-10544 add IS_EXTERNAL and DESCRIPTION_URL column to RULES table X-Git-Tag: 7.5~1327 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=99044b2859e0867684a6f5bb72129fdbd341cc4a;p=sonarqube.git SONAR-10544 add IS_EXTERNAL and DESCRIPTION_URL column to RULES table --- diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl index d15982719de..4306a0d22f6 100644 --- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl +++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl @@ -186,8 +186,10 @@ CREATE TABLE "RULES" ( "PLUGIN_NAME" VARCHAR(255) NOT NULL, "DESCRIPTION" VARCHAR(16777215), "DESCRIPTION_FORMAT" VARCHAR(20), + "DESCRIPTION_URL" VARCHAR(256), "PRIORITY" INTEGER, "IS_TEMPLATE" BOOLEAN DEFAULT FALSE, + "IS_EXTERNAL" BOOLEAN DEFAULT FALSE, "TEMPLATE_ID" INTEGER, "PLUGIN_CONFIG_KEY" VARCHAR(200), "NAME" VARCHAR(200), diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java index c291d134b97..1b072c46594 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java @@ -42,11 +42,13 @@ public class RuleDefinitionDto { private String ruleKey; private String description; private RuleDto.Format descriptionFormat; + private String descriptionURL; private RuleStatus status; private String name; private String configKey; private Integer severity; private boolean isTemplate; + private boolean isExternal; private String language; private Integer templateId; private String defRemediationFunction; @@ -120,6 +122,15 @@ public class RuleDefinitionDto { return this; } + public String getDescriptionURL() { + return descriptionURL; + } + + public RuleDefinitionDto setDescriptionURL(String descriptionURL) { + this.descriptionURL = descriptionURL; + return this; + } + public RuleDto.Format getDescriptionFormat() { return descriptionFormat; } @@ -185,6 +196,16 @@ public class RuleDefinitionDto { return this; } + + public boolean isExternal() { + return isExternal; + } + + public RuleDefinitionDto setIsExternal(boolean isExternal) { + this.isExternal = isExternal; + return this; + } + @CheckForNull public String getLanguage() { return language; diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml index 44b4ecf66a5..0d5acbf4bba 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml @@ -9,11 +9,13 @@ r.plugin_name as "repositoryKey", r.description, r.description_format as "descriptionFormat", + r.description_url as "descriptionURL", r.status, r.name, r.plugin_config_key as "configKey", r.priority as "severity", r.is_template as "isTemplate", + r.is_external as "isExternal", r.language as "language", r.template_id as "templateId", r.def_remediation_function as "defRemediationFunction", @@ -290,11 +292,13 @@ plugin_name, description, description_format, + description_url, status, name, plugin_config_key, priority, is_template, + is_external, language, template_id, def_remediation_function, @@ -313,11 +317,13 @@ #{repositoryKey,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{descriptionFormat,jdbcType=VARCHAR}, + #{descriptionURL,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{configKey,jdbcType=VARCHAR}, #{severity,jdbcType=INTEGER}, #{isTemplate,jdbcType=BOOLEAN}, + #{isExternal,jdbcType=BOOLEAN}, #{language,jdbcType=VARCHAR}, #{templateId,jdbcType=INTEGER}, #{defRemediationFunction,jdbcType=VARCHAR}, @@ -339,11 +345,13 @@ plugin_name=#{repositoryKey,jdbcType=VARCHAR}, description=#{description,jdbcType=VARCHAR}, description_format=#{descriptionFormat,jdbcType=VARCHAR}, + description_url=#{descriptionURL,jdbcType=VARCHAR}, status=#{status,jdbcType=VARCHAR}, name=#{name,jdbcType=VARCHAR}, plugin_config_key=#{configKey,jdbcType=VARCHAR}, priority=#{severity,jdbcType=INTEGER}, is_template=#{isTemplate,jdbcType=BOOLEAN}, + is_external=#{isExternal,jdbcType=BOOLEAN}, language=#{language,jdbcType=VARCHAR}, template_id=#{templateId,jdbcType=INTEGER}, def_remediation_function=#{defRemediationFunction,jdbcType=VARCHAR}, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java index b585954a785..44e469219f9 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java @@ -476,10 +476,12 @@ public class RuleDaoTest { .setName("new name") .setDescription("new description") .setDescriptionFormat(RuleDto.Format.MARKDOWN) + .setDescriptionURL("https://eslint.org/docs/rules/no-cond-assign") .setStatus(RuleStatus.DEPRECATED) .setConfigKey("NewConfigKey") .setSeverity(Severity.INFO) .setIsTemplate(true) + .setIsExternal(true) .setLanguage("dart") .setTemplateId(3) .setDefRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString()) @@ -499,6 +501,7 @@ public class RuleDaoTest { assertThat(ruleDto.getName()).isEqualTo("new name"); assertThat(ruleDto.getDescription()).isEqualTo("new description"); assertThat(ruleDto.getDescriptionFormat()).isEqualTo(RuleDto.Format.MARKDOWN); + assertThat(ruleDto.getDescriptionURL()).isEqualTo("https://eslint.org/docs/rules/no-cond-assign"); assertThat(ruleDto.getStatus()).isEqualTo(RuleStatus.DEPRECATED); assertThat(ruleDto.getRuleKey()).isEqualTo("NewRuleKey"); assertThat(ruleDto.getRepositoryKey()).isEqualTo("plugin"); @@ -506,6 +509,7 @@ public class RuleDaoTest { assertThat(ruleDto.getSeverity()).isEqualTo(0); assertThat(ruleDto.getLanguage()).isEqualTo("dart"); assertThat(ruleDto.isTemplate()).isTrue(); + assertThat(ruleDto.isExternal()).isTrue(); assertThat(ruleDto.getTemplateId()).isEqualTo(3); assertThat(ruleDto.getDefRemediationFunction()).isEqualTo("LINEAR_OFFSET"); assertThat(ruleDto.getDefRemediationGapMultiplier()).isEqualTo("5d"); @@ -529,10 +533,12 @@ public class RuleDaoTest { .setName("new name") .setDescription("new description") .setDescriptionFormat(RuleDto.Format.MARKDOWN) + .setDescriptionURL("https://eslint.org/docs/rules/no-cond-assign") .setStatus(RuleStatus.DEPRECATED) .setConfigKey("NewConfigKey") .setSeverity(Severity.INFO) .setIsTemplate(true) + .setIsExternal(true) .setLanguage("dart") .setTemplateId(3) .setDefRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString()) @@ -551,6 +557,7 @@ public class RuleDaoTest { assertThat(ruleDto.getName()).isEqualTo("new name"); assertThat(ruleDto.getDescription()).isEqualTo("new description"); assertThat(ruleDto.getDescriptionFormat()).isEqualTo(RuleDto.Format.MARKDOWN); + assertThat(ruleDto.getDescriptionURL()).isEqualTo("https://eslint.org/docs/rules/no-cond-assign"); assertThat(ruleDto.getStatus()).isEqualTo(RuleStatus.DEPRECATED); assertThat(ruleDto.getRuleKey()).isEqualTo("NewRuleKey"); assertThat(ruleDto.getRepositoryKey()).isEqualTo("plugin"); @@ -558,6 +565,7 @@ public class RuleDaoTest { assertThat(ruleDto.getSeverity()).isEqualTo(0); assertThat(ruleDto.getLanguage()).isEqualTo("dart"); assertThat(ruleDto.isTemplate()).isTrue(); + assertThat(ruleDto.isExternal()).isTrue(); assertThat(ruleDto.getTemplateId()).isEqualTo(3); assertThat(ruleDto.getDefRemediationFunction()).isEqualTo("LINEAR_OFFSET"); assertThat(ruleDto.getDefRemediationGapMultiplier()).isEqualTo("5d"); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/AddRuleExternal.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/AddRuleExternal.java new file mode 100644 index 00000000000..236f2bbefcc --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/AddRuleExternal.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.server.platform.db.migration.version.v72; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.def.BooleanColumnDef; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import java.sql.SQLException; + +public class AddRuleExternal extends DdlChange { + + public AddRuleExternal(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddColumnsBuilder(getDialect(), "rules") + .addColumn(BooleanColumnDef.newBooleanColumnDefBuilder() + .setColumnName("is_external") + .setIsNullable(true) + .setDefaultValue(false) + .build()) + .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder() + .setColumnName("description_url") + .setIsNullable(true) + .setLimit(256) + .build()) + .build()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72.java index 2303e9e1d89..dbbb14df39b 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72.java @@ -30,6 +30,6 @@ public class DbVersion72 implements DbVersion { .add(2100, "Increase size of USERS.CRYPTED_PASSWORD", IncreaseCryptedPasswordSize.class) .add(2101, "Add HASH_METHOD to table users", AddHashMethodToUsersTable.class) .add(2102, "Populate HASH_METHOD on table users", PopulateHashMethodOnUsers.class) - ; + .add(2103, "Add isExternal boolean and description_url to rules", AddRuleExternal.class); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/AddRuleExternalTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/AddRuleExternalTest.java new file mode 100644 index 00000000000..850bf0c7610 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/AddRuleExternalTest.java @@ -0,0 +1,58 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.server.platform.db.migration.version.v72; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.db.CoreDbTester; + +import java.sql.SQLException; + +import static java.sql.Types.BOOLEAN; +import static java.sql.Types.VARCHAR; +import static org.junit.rules.ExpectedException.none; +import static org.sonar.db.CoreDbTester.createForSchema; + +public class AddRuleExternalTest { + @Rule + public final CoreDbTester dbTester = createForSchema(AddRuleExternalTest.class, "rules.sql"); + + @Rule + public ExpectedException expectedException = none(); + + private AddRuleExternal underTest = new AddRuleExternal(dbTester.database()); + + @Test + public void column_are_added_to_table() throws SQLException { + underTest.execute(); + dbTester.assertColumnDefinition("rules", "is_external", BOOLEAN, null, true); + dbTester.assertColumnDefinition("rules", "description_url", VARCHAR, 256, true); + } + + @Test + public void migration_is_not_reentrant() throws SQLException { + underTest.execute(); + + expectedException.expect(IllegalStateException.class); + + underTest.execute(); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72Test.java index 9af6646d5a1..31fa3c4f6ee 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72Test.java @@ -28,13 +28,13 @@ public class DbVersion72Test { private DbVersion72 underTest = new DbVersion72(); @Test - public void migrationNumber_starts_at_2100() { + public void migrationNumber_starts_at_2000() { verifyMinimumMigrationNumber(underTest, 2100); } @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 3); + verifyMigrationCount(underTest, 4); } } diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/AddRuleExternalTest/rules.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/AddRuleExternalTest/rules.sql new file mode 100644 index 00000000000..f661e2fc5c4 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/AddRuleExternalTest/rules.sql @@ -0,0 +1,25 @@ +CREATE TABLE "RULES" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "PLUGIN_KEY" VARCHAR(200), + "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL, + "PLUGIN_NAME" VARCHAR(255) NOT NULL, + "DESCRIPTION" VARCHAR(16777215), + "DESCRIPTION_FORMAT" VARCHAR(20), + "PRIORITY" INTEGER, + "IS_TEMPLATE" BOOLEAN DEFAULT FALSE, + "TEMPLATE_ID" INTEGER, + "PLUGIN_CONFIG_KEY" VARCHAR(200), + "NAME" VARCHAR(200), + "STATUS" VARCHAR(40), + "LANGUAGE" VARCHAR(20), + "SCOPE" VARCHAR(20) NOT NULL, + "DEF_REMEDIATION_FUNCTION" VARCHAR(20), + "DEF_REMEDIATION_GAP_MULT" VARCHAR(20), + "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20), + "GAP_DESCRIPTION" VARCHAR(4000), + "SYSTEM_TAGS" VARCHAR(4000), + "RULE_TYPE" TINYINT, + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT +); +CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES" ("PLUGIN_NAME", "PLUGIN_RULE_KEY");