]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16598 Add new column generic concepts
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Tue, 5 Jul 2022 12:46:41 +0000 (14:46 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 8 Jul 2022 20:02:47 +0000 (20:02 +0000)
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v96/AddGenericConceptsColumnToRuleTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v96/DbVersion96.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v96/AddGenericConceptsColumnToRuleTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v96/AddGenericConceptsColumnToRuleTableTest/schema.sql [new file with mode: 0644]

index 281bafab250dd330174337bb812c3a27bd5c6108..5f0ef17e6f9c298f86786b17bcc730a0e1b8fbfd 100644 (file)
@@ -863,7 +863,8 @@ CREATE TABLE "RULES"(
     "AD_HOC_NAME" CHARACTER VARYING(200),
     "AD_HOC_DESCRIPTION" CHARACTER LARGE OBJECT,
     "AD_HOC_SEVERITY" CHARACTER VARYING(10),
-    "AD_HOC_TYPE" TINYINT
+    "AD_HOC_TYPE" TINYINT,
+    "GENERIC_CONCEPTS" CHARACTER VARYING(255)
 );
 ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("UUID");
 CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY" NULLS FIRST, "PLUGIN_NAME" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v96/AddGenericConceptsColumnToRuleTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v96/AddGenericConceptsColumnToRuleTable.java
new file mode 100644 (file)
index 0000000..5011ca6
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.v96;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddGenericConceptsColumnToRuleTable extends DdlChange {
+
+  static final String COLUMN_GENERIC_CONCEPTS_KEY = "generic_concepts";
+
+  static final String RULE_TABLE = "rules";
+
+  public AddGenericConceptsColumnToRuleTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(DdlChange.Context context) throws SQLException {
+    try (Connection connection = getDatabase().getDataSource().getConnection()) {
+      if (!DatabaseUtils.tableColumnExists(connection, RULE_TABLE, COLUMN_GENERIC_CONCEPTS_KEY)) {
+        context.execute(new AddColumnsBuilder(getDialect(), RULE_TABLE)
+          .addColumn(newVarcharColumnDefBuilder().setColumnName(COLUMN_GENERIC_CONCEPTS_KEY).setIsNullable(true).setLimit(255).build())
+          .build());
+      }
+    }
+  }
+
+}
index e8651bfc078b9dedc6558d61bb87b4f899110518..043a8e385954d10054a4042d0a830461cc03304c 100644 (file)
@@ -32,6 +32,7 @@ public class DbVersion96 implements DbVersion {
       .add(6502, "Drop unique index uniq_rule_desc_sections_kee", DropIndexForRuleDescSection.class)
       .add(6503, "Create unique uniq_rule_desc_sections", CreateIndexForRuleDescSections.class)
       .add(6504, "Add column 'expiration_date' to 'user_tokens'", AddExpirationDateColumnToUserTokens.class)
+      .add(6505, "Add column 'generic_concepts' to 'rules'", AddGenericConceptsColumnToRuleTable.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v96/AddGenericConceptsColumnToRuleTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v96/AddGenericConceptsColumnToRuleTableTest.java
new file mode 100644 (file)
index 0000000..4bcc490
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.v96;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.sonar.db.CoreDbTester.createForSchema;
+import static org.sonar.server.platform.db.migration.version.v96.AddGenericConceptsColumnToRuleTable.COLUMN_GENERIC_CONCEPTS_KEY;
+import static org.sonar.server.platform.db.migration.version.v96.AddGenericConceptsColumnToRuleTable.RULE_TABLE;
+
+public class AddGenericConceptsColumnToRuleTableTest {
+  @Rule
+  public final CoreDbTester db = createForSchema(AddGenericConceptsColumnToRuleTableTest.class, "schema.sql");
+
+  private final AddGenericConceptsColumnToRuleTable addGenericConceptsColumnToRuleTable = new AddGenericConceptsColumnToRuleTable(db.database());
+
+  @Test
+  public void column_generic_concepts_should_be_added() throws SQLException {
+    db.assertColumnDoesNotExist(RULE_TABLE, COLUMN_GENERIC_CONCEPTS_KEY);
+
+    addGenericConceptsColumnToRuleTable.execute();
+
+    db.assertColumnDefinition(RULE_TABLE, COLUMN_GENERIC_CONCEPTS_KEY, Types.VARCHAR, 255, true);
+  }
+
+  @Test
+  public void migration_should_be_reentrant() throws SQLException {
+    db.assertColumnDoesNotExist(RULE_TABLE, COLUMN_GENERIC_CONCEPTS_KEY);
+
+    addGenericConceptsColumnToRuleTable.execute();
+    addGenericConceptsColumnToRuleTable.execute();
+
+    db.assertColumnDefinition(RULE_TABLE, COLUMN_GENERIC_CONCEPTS_KEY, Types.VARCHAR, 255, true);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v96/AddGenericConceptsColumnToRuleTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v96/AddGenericConceptsColumnToRuleTableTest/schema.sql
new file mode 100644 (file)
index 0000000..8346f94
--- /dev/null
@@ -0,0 +1,40 @@
+CREATE TABLE "RULES"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "NAME" CHARACTER VARYING(200),
+    "PLUGIN_RULE_KEY" CHARACTER VARYING(200) NOT NULL,
+    "PLUGIN_KEY" CHARACTER VARYING(200),
+    "PLUGIN_CONFIG_KEY" CHARACTER VARYING(200),
+    "PLUGIN_NAME" CHARACTER VARYING(255) NOT NULL,
+    "SCOPE" CHARACTER VARYING(20) NOT NULL,
+    "PRIORITY" INTEGER,
+    "STATUS" CHARACTER VARYING(40),
+    "LANGUAGE" CHARACTER VARYING(20),
+    "DEF_REMEDIATION_FUNCTION" CHARACTER VARYING(20),
+    "DEF_REMEDIATION_GAP_MULT" CHARACTER VARYING(20),
+    "DEF_REMEDIATION_BASE_EFFORT" CHARACTER VARYING(20),
+    "GAP_DESCRIPTION" CHARACTER VARYING(4000),
+    "SYSTEM_TAGS" CHARACTER VARYING(4000),
+    "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+    "DESCRIPTION_FORMAT" CHARACTER VARYING(20),
+    "RULE_TYPE" TINYINT,
+    "SECURITY_STANDARDS" CHARACTER VARYING(4000),
+    "IS_AD_HOC" BOOLEAN NOT NULL,
+    "IS_EXTERNAL" BOOLEAN NOT NULL,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "TEMPLATE_UUID" CHARACTER VARYING(40),
+    "NOTE_DATA" CHARACTER LARGE OBJECT,
+    "NOTE_USER_UUID" CHARACTER VARYING(255),
+    "NOTE_CREATED_AT" BIGINT,
+    "NOTE_UPDATED_AT" BIGINT,
+    "REMEDIATION_FUNCTION" CHARACTER VARYING(20),
+    "REMEDIATION_GAP_MULT" CHARACTER VARYING(20),
+    "REMEDIATION_BASE_EFFORT" CHARACTER VARYING(20),
+    "TAGS" CHARACTER VARYING(4000),
+    "AD_HOC_NAME" CHARACTER VARYING(200),
+    "AD_HOC_DESCRIPTION" CHARACTER LARGE OBJECT,
+    "AD_HOC_SEVERITY" CHARACTER VARYING(10),
+    "AD_HOC_TYPE" TINYINT
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY" NULLS FIRST, "PLUGIN_NAME" NULLS FIRST);