]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13221 change PK to uuid of ACTIVE_RULE_PARAMETERS table
authorJacek <jacek.poreda@sonarsource.com>
Thu, 16 Apr 2020 12:30:46 +0000 (14:30 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 25 May 2020 20:05:19 +0000 (20:05 +0000)
26 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleParamDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddUuidColumnToActiveRuleParametersTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropIdColumnOfActiveRuleParametersTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/MakeActiveRuleParametersUuidColumnNotNullable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/PopulateActiveRuleParametersUuid.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddUuidColumnToActiveRuleParametersTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropIdColumnOfActiveRuleParametersTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/MakeActiveRuleParametersUuidColumnNotNullableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/PopulateActiveRuleParametersUuidTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddUuidColumnToActiveRuleParametersTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropIdColumnOfActiveRuleParametersTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/MakeActiveRuleParametersUuidColumnNotNullableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/PopulateActiveRuleParametersUuidTest/schema.sql [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java

index 8090f55a75b48e23f975391f2d3a148506bd441d..879a72ab987ad4111b9f67f7b21a5d3d2442d6b3 100644 (file)
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.function.Consumer;
+import org.sonar.core.util.UuidFactory;
 import org.sonar.db.Dao;
 import org.sonar.db.DatabaseUtils;
 import org.sonar.db.DbSession;
@@ -47,6 +48,12 @@ public class ActiveRuleDao implements Dao {
   private static final String ACTIVE_RULE_PARAM_IS_NOT_PERSISTED = "ActiveRuleParam is not persisted";
   private static final String ACTIVE_RULE_PARAM_IS_ALREADY_PERSISTED = "ActiveRuleParam is already persisted";
 
+  private final UuidFactory uuidFactory;
+
+  public ActiveRuleDao(UuidFactory uuidFactory) {
+    this.uuidFactory = uuidFactory;
+  }
+
   public Optional<ActiveRuleDto> selectByKey(DbSession dbSession, ActiveRuleKey key) {
     return Optional.ofNullable(mapper(dbSession).selectByKey(key.getRuleProfileUuid(), key.getRuleKey().repository(), key.getRuleKey().rule()));
   }
@@ -143,26 +150,27 @@ public class ActiveRuleDao implements Dao {
 
   public ActiveRuleParamDto insertParam(DbSession dbSession, ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam) {
     checkArgument(activeRule.getId() != null, ACTIVE_RULE_IS_NOT_PERSISTED);
-    checkArgument(activeRuleParam.getId() == null, ACTIVE_RULE_PARAM_IS_ALREADY_PERSISTED);
+    checkArgument(activeRuleParam.getUuid() == null, ACTIVE_RULE_PARAM_IS_ALREADY_PERSISTED);
     Preconditions.checkNotNull(activeRuleParam.getRulesParameterId(), RULE_PARAM_IS_NOT_PERSISTED);
 
     activeRuleParam.setActiveRuleId(activeRule.getId());
+    activeRuleParam.setUuid(uuidFactory.create());
     mapper(dbSession).insertParameter(activeRuleParam);
     return activeRuleParam;
   }
 
   public void updateParam(DbSession dbSession, ActiveRuleParamDto activeRuleParam) {
-    Preconditions.checkNotNull(activeRuleParam.getId(), ACTIVE_RULE_PARAM_IS_NOT_PERSISTED);
+    Preconditions.checkNotNull(activeRuleParam.getUuid(), ACTIVE_RULE_PARAM_IS_NOT_PERSISTED);
     mapper(dbSession).updateParameter(activeRuleParam);
   }
 
   public void deleteParam(DbSession dbSession, ActiveRuleParamDto activeRuleParam) {
-    Preconditions.checkNotNull(activeRuleParam.getId(), ACTIVE_RULE_PARAM_IS_NOT_PERSISTED);
-    deleteParamById(dbSession, activeRuleParam.getId());
+    Preconditions.checkNotNull(activeRuleParam.getUuid(), ACTIVE_RULE_PARAM_IS_NOT_PERSISTED);
+    deleteParamById(dbSession, activeRuleParam.getUuid());
   }
 
-  public void deleteParamById(DbSession dbSession, int id) {
-    mapper(dbSession).deleteParameter(id);
+  public void deleteParamById(DbSession dbSession, String uuid) {
+    mapper(dbSession).deleteParameter(uuid);
   }
 
   public void deleteParamsByRuleParamOfAllOrganizations(DbSession dbSession, RuleParamDto param) {
index dc3141f2dae035c6f60734fe03b0acb6b3a07ae4..d159244eb821dd341dc29a0cc232babb58a58822 100644 (file)
@@ -69,7 +69,7 @@ public interface ActiveRuleMapper {
 
   void deleteParametersByRuleProfileUuids(@Param("rulesProfileUuids") Collection<String> rulesProfileUuids);
 
-  void deleteParameter(int activeRuleParamId);
+  void deleteParameter(String activeRuleParamUuid);
 
   void deleteParamsByActiveRuleIds(@Param("activeRuleIds") Collection<Integer> activeRuleIds);
 
index f65c5a60a1ec18ecf3b65787ed313ad8c36b28a5..64e61e9524b42331a3c40d9013d083658e8ba401 100644 (file)
@@ -29,18 +29,18 @@ import org.sonar.db.rule.RuleParamDto;
 
 public class ActiveRuleParamDto {
 
-  private Integer id;
+  private String uuid;
   private Integer activeRuleId;
   private Integer rulesParameterId;
   private String kee;
   private String value;
 
-  public Integer getId() {
-    return id;
+  public String getUuid() {
+    return uuid;
   }
 
-  public ActiveRuleParamDto setId(Integer id) {
-    this.id = id;
+  public ActiveRuleParamDto setUuid(String uuid) {
+    this.uuid = uuid;
     return this;
   }
 
index 2a7b4f866eed7cc06b336e522377a10d21b0792e..515cbe79661905ffb50e800bde838b3c4cec9e57 100644 (file)
   <!-- Parameters -->
 
   <sql id="activeRuleParamColumns">
-    p.id,
+    p.uuid,
     p.active_rule_id as activeRuleId,
     p.rules_parameter_id as rulesParameterId,
     p.rules_parameter_key as kee,
     p.value as value
   </sql>
 
-  <insert id="insertParameter" parameterType="ActiveRuleParam" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insertParameter" parameterType="ActiveRuleParam" useGeneratedKeys="false">
     insert into active_rule_parameters (
+      uuid,
       active_rule_id,
       rules_parameter_id,
       rules_parameter_key,
       value
     ) values (
+      #{uuid, jdbcType=VARCHAR},
       #{activeRuleId, jdbcType=BIGINT},
       #{rulesParameterId, jdbcType=BIGINT},
       #{key, jdbcType=VARCHAR},
   <update id="updateParameter" parameterType="ActiveRuleParam">
     UPDATE active_rule_parameters SET
     value=#{value, jdbcType=VARCHAR}
-    WHERE id=#{id, jdbcType=BIGINT}
+    WHERE uuid=#{uuid, jdbcType=VARCHAR}
   </update>
 
   <delete id="deleteParameters" parameterType="int">
-    DELETE FROM active_rule_parameters WHERE active_rule_id=#{id, jdbcType=BIGINT}
+    DELETE FROM active_rule_parameters WHERE active_rule_id=#{activeRuleId, jdbcType=BIGINT}
   </delete>
 
   <delete id="deleteParametersByRuleProfileUuids" parameterType="String">
     )
   </delete>
 
-  <delete id="deleteParameter" parameterType="int">
-    DELETE FROM active_rule_parameters WHERE id=#{id, jdbcType=BIGINT}
+  <delete id="deleteParameter" parameterType="String">
+    DELETE FROM active_rule_parameters WHERE uuid=#{uuid, jdbcType=VARCHAR}
   </delete>
 
   <delete id="deleteParamsByActiveRuleIds" parameterType="Integer">
index 5bfa4ce355ef8ad0561a8f6023948e14c3a078bd..ffca4c9f54ca7112c63a2ba8aab59bf86f1f8c96 100644 (file)
@@ -14,13 +14,13 @@ CREATE TABLE "SCHEMA_MIGRATIONS"(
 );
 
 CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
     "ACTIVE_RULE_ID" INTEGER NOT NULL,
     "RULES_PARAMETER_ID" INTEGER NOT NULL,
     "VALUE" VARCHAR(4000),
-    "RULES_PARAMETER_KEY" VARCHAR(128)
+    "RULES_PARAMETER_KEY" VARCHAR(128),
+    "UUID" VARCHAR(40) NOT NULL
 );
-ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "PK_ACTIVE_RULE_PARAMETERS" PRIMARY KEY("ID");
+ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "PK_ACTIVE_RULE_PARAMETERS" PRIMARY KEY("UUID");
 CREATE INDEX "IX_ARP_ON_ACTIVE_RULE_ID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_ID");
 
 CREATE TABLE "ACTIVE_RULES"(
index 0e9c4507dae22be3247361eeb1b36075dd894ad4..805cf94307f6b926342661ff60cc685b3c9b4ca3 100644 (file)
@@ -28,11 +28,11 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.sonar.api.impl.utils.TestSystem2;
 import org.sonar.api.rule.Severity;
 import org.sonar.api.rules.RuleType;
 import org.sonar.api.server.rule.RuleParamType;
 import org.sonar.api.utils.System2;
-import org.sonar.api.impl.utils.TestSystem2;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
@@ -462,7 +462,7 @@ public class ActiveRuleDaoTest {
     List<ActiveRuleParamDto> reloaded = underTest.selectParamsByActiveRuleId(dbSession, activeRule.getId());
     assertThat(reloaded).hasSize(1);
     assertThat(reloaded.get(0))
-      .matches(p -> Objects.equals(p.getId(), activeRuleParam.getId()))
+      .matches(p -> Objects.equals(p.getUuid(), activeRuleParam.getUuid()))
       .matches(p -> p.getKey().equals(activeRuleParam.getKey()))
       .matches(p -> p.getActiveRuleId().equals(activeRule.getId()))
       .matches(p -> p.getRulesParameterId().equals(rule1Param1.getId()))
@@ -486,7 +486,7 @@ public class ActiveRuleDaoTest {
 
     underTest.insertParam(dbSession,
       createFor(profile1, rule1).setId(100),
-      ActiveRuleParamDto.createFor(rule1Param1).setValue("activeValue1").setId(100));
+      ActiveRuleParamDto.createFor(rule1Param1).setValue("activeValue1").setUuid("uuid-1"));
   }
 
   @Test
@@ -511,7 +511,7 @@ public class ActiveRuleDaoTest {
     List<ActiveRuleParamDto> reloaded = underTest.selectParamsByActiveRuleId(dbSession, activeRule.getId());
     assertThat(reloaded).hasSize(1);
     assertThat(reloaded.get(0))
-      .matches(p -> Objects.equals(p.getId(), activeRuleParam.getId()))
+      .matches(p -> Objects.equals(p.getUuid(), activeRuleParam.getUuid()))
       .matches(p -> p.getKey().equals(activeRuleParam.getKey()))
       .matches(p -> p.getActiveRuleId().equals(activeRule.getId()))
       .matches(p -> p.getRulesParameterId().equals(rule1Param1.getId()))
index 0b35213e766f6893874cce188c54c1a54f6e101d..f17f34fc2196c4ee6b9bae571ce21674c37acfcc 100644 (file)
@@ -21,6 +21,12 @@ package org.sonar.server.platform.db.migration.version.v83;
 
 import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
 import org.sonar.server.platform.db.migration.version.DbVersion;
+import org.sonar.server.platform.db.migration.version.v83.activeruleparameters.AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.activeruleparameters.AddUuidColumnToActiveRuleParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.activeruleparameters.DropIdColumnOfActiveRuleParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.activeruleparameters.DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.activeruleparameters.MakeActiveRuleParametersUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.activeruleparameters.PopulateActiveRuleParametersUuid;
 import org.sonar.server.platform.db.migration.version.v83.ceactivity.AddPrimaryKeyOnUuidColumnOfCeActivityTable;
 import org.sonar.server.platform.db.migration.version.v83.ceactivity.DropIdColumnOfCeActivityTable;
 import org.sonar.server.platform.db.migration.version.v83.ceactivity.DropPrimaryKeyOnIdColumnOfCeActivityTable;
@@ -108,6 +114,14 @@ public class DbVersion83 implements DbVersion {
       .add(3425, "Drop primary key on 'ID' column of 'DUPLICATIONS_INDEX' table", DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable.class)
       .add(3426, "Add primary key on 'UUID' column of 'DUPLICATIONS_INDEX' table", AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable.class)
       .add(3427, "Drop column 'ID' of 'DUPLICATIONS_INDEX' table", DropIdColumnOfDuplicationsIndexTable.class)
+
+      // Migration of ACTIVE_RULE_PARAMS table
+      .add(3428, "Add 'uuid' column for 'ACTIVE_RULE_PARAMS' table", AddUuidColumnToActiveRuleParametersTable.class)
+      .add(3429, "Populate 'uuid' column for 'ACTIVE_RULE_PARAMS' table", PopulateActiveRuleParametersUuid.class)
+      .add(3430, "Make 'uuid' column not nullable for 'ACTIVE_RULE_PARAMS' table", MakeActiveRuleParametersUuidColumnNotNullable.class)
+      .add(3431, "Drop primary key on 'ID' column of 'ACTIVE_RULE_PARAMS' table", DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable.class)
+      .add(3432, "Add primary key on 'UUID' column of 'ACTIVE_RULE_PARAMS' table", AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable.class)
+      .add(3433, "Drop column 'ID' of 'ACTIVE_RULE_PARAMS' table", DropIdColumnOfActiveRuleParametersTable.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable.java
new file mode 100644 (file)
index 0000000..002d8ac
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.activeruleparameters;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder;
+
+public class AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable extends DdlChange {
+
+  public AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddPrimaryKeyBuilder("active_rule_parameters", "uuid").build());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddUuidColumnToActiveRuleParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddUuidColumnToActiveRuleParametersTable.java
new file mode 100644 (file)
index 0000000..76f90fe
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.activeruleparameters;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+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 static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddUuidColumnToActiveRuleParametersTable extends DdlChange {
+  private static final String TABLE = "active_rule_parameters";
+
+  private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+    .setColumnName("uuid")
+    .setIsNullable(true)
+    .setDefaultValue(null)
+    .setLimit(VarcharColumnDef.UUID_SIZE)
+    .build();
+
+  public AddUuidColumnToActiveRuleParametersTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+      .addColumn(uuidColumnDefinition)
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropIdColumnOfActiveRuleParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropIdColumnOfActiveRuleParametersTable.java
new file mode 100644 (file)
index 0000000..a158c36
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.activeruleparameters;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIdColumnOfActiveRuleParametersTable extends DdlChange {
+
+  public DropIdColumnOfActiveRuleParametersTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new DropColumnsBuilder(getDialect(), "active_rule_parameters", "id").build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable.java
new file mode 100644 (file)
index 0000000..d8c0a30
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.activeruleparameters;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable extends DdlChange {
+
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator;
+
+  public DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+    super(db);
+    this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(dropPrimaryKeySqlGenerator.generate("active_rule_parameters", "active_rule_parameters", "id"));
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/MakeActiveRuleParametersUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/MakeActiveRuleParametersUuidColumnNotNullable.java
new file mode 100644 (file)
index 0000000..ba97d59
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.activeruleparameters;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeActiveRuleParametersUuidColumnNotNullable extends DdlChange {
+  private static final String TABLE = "active_rule_parameters";
+
+  private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+    .setColumnName("uuid")
+    .setIsNullable(false)
+    .setDefaultValue(null)
+    .setLimit(VarcharColumnDef.UUID_SIZE)
+    .build();
+
+  public MakeActiveRuleParametersUuidColumnNotNullable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+      .updateColumn(uuidColumnDefinition)
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/PopulateActiveRuleParametersUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/PopulateActiveRuleParametersUuid.java
new file mode 100644 (file)
index 0000000..13bba34
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.activeruleparameters;
+
+import java.sql.SQLException;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class PopulateActiveRuleParametersUuid extends DataChange {
+
+  private final UuidFactory uuidFactory;
+
+  public PopulateActiveRuleParametersUuid(Database db, UuidFactory uuidFactory) {
+    super(db);
+    this.uuidFactory = uuidFactory;
+  }
+
+  @Override
+  protected void execute(Context context) throws SQLException {
+    MassUpdate massUpdate = context.prepareMassUpdate();
+
+    massUpdate.select("select id from active_rule_parameters where uuid is null");
+    massUpdate.update("update active_rule_parameters set uuid = ? where id = ?");
+
+    massUpdate.execute((row, update) -> {
+      update.setString(1, uuidFactory.create());
+      update.setLong(2, row.getLong(1));
+      return true;
+    });
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTableTest.java
new file mode 100644 (file)
index 0000000..984ec7b
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.activeruleparameters;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertPrimaryKey("active_rule_parameters", "pk_active_rule_parameters", "uuid");
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddUuidColumnToActiveRuleParametersTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddUuidColumnToActiveRuleParametersTest.java
new file mode 100644 (file)
index 0000000..3ac39c0
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.activeruleparameters;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddUuidColumnToActiveRuleParametersTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToActiveRuleParametersTest.class, "schema.sql");
+
+  private DdlChange underTest = new AddUuidColumnToActiveRuleParametersTable(db.database());
+
+  @Before
+  public void setup() {
+    insertActiveRuleParameter(1L);
+    insertActiveRuleParameter(2L);
+    insertActiveRuleParameter(3L);
+  }
+
+  @Test
+  public void add_uuid_column_to_active_rule_parameters() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("active_rule_parameters", "uuid", Types.VARCHAR, 40, true);
+
+    assertThat(db.countSql("select count(id) from active_rule_parameters"))
+      .isEqualTo(3);
+  }
+
+  private void insertActiveRuleParameter(Long id) {
+    db.executeInsert("active_rule_parameters",
+      "id", id,
+      "active_rule_id", id + 2,
+      "rules_parameter_id", id + 3);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropIdColumnOfActiveRuleParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropIdColumnOfActiveRuleParametersTableTest.java
new file mode 100644 (file)
index 0000000..2f567d0
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.activeruleparameters;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropIdColumnOfActiveRuleParametersTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfActiveRuleParametersTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new DropIdColumnOfActiveRuleParametersTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDoesNotExist("active_rule_parameters", "id");
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest.java
new file mode 100644 (file)
index 0000000..7f0e3e2
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.activeruleparameters;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+import org.sonar.server.platform.db.migration.version.v83.util.GetConstraintHelper;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest {
+
+  private static final String TABLE_NAME = "active_rule_parameters";
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest.class, "schema.sql");
+
+  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new GetConstraintHelper(db.database()));
+
+  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable(db.database(), dropPrimaryKeySqlGenerator);
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertNoPrimaryKey(TABLE_NAME);
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/MakeActiveRuleParametersUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/MakeActiveRuleParametersUuidColumnNotNullableTest.java
new file mode 100644 (file)
index 0000000..79307cd
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.activeruleparameters;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeActiveRuleParametersUuidColumnNotNullableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(MakeActiveRuleParametersUuidColumnNotNullableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new MakeActiveRuleParametersUuidColumnNotNullable(db.database());
+
+  @Test
+  public void created_at_and_uuid_columns_are_not_null() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("active_rule_parameters", "uuid", VARCHAR, null, false);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/PopulateActiveRuleParametersUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/PopulateActiveRuleParametersUuidTest.java
new file mode 100644 (file)
index 0000000..a6a4aeb
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.activeruleparameters;
+
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PopulateActiveRuleParametersUuidTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(PopulateActiveRuleParametersUuidTest.class, "schema.sql");
+
+  private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+  private DataChange underTest = new PopulateActiveRuleParametersUuid(db.database(), uuidFactory);
+
+  @Test
+  public void populate_uuids() throws SQLException {
+    insertActiveRuleParameter(1L);
+    insertActiveRuleParameter(2L);
+    insertActiveRuleParameter(3L);
+
+    underTest.execute();
+
+    verifyUuidsAreNotNull();
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    insertActiveRuleParameter(1L);
+    insertActiveRuleParameter(2L);
+    insertActiveRuleParameter(3L);
+
+    underTest.execute();
+    // re-entrant
+    underTest.execute();
+
+    verifyUuidsAreNotNull();
+  }
+
+  private void verifyUuidsAreNotNull() {
+    assertThat(db.select("select uuid from active_rule_parameters")
+      .stream()
+      .map(row -> row.get("UUID"))
+      .filter(Objects::isNull)
+      .collect(Collectors.toList())).isEmpty();
+  }
+
+  private void insertActiveRuleParameter(Long id) {
+    db.executeInsert("active_rule_parameters",
+      "id", id,
+      "active_rule_id", id + 2,
+      "rules_parameter_id", id + 3);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTableTest/schema.sql
new file mode 100644 (file)
index 0000000..814cb67
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "ACTIVE_RULE_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_ID" INTEGER NOT NULL,
+    "VALUE" VARCHAR(4000),
+    "RULES_PARAMETER_KEY" VARCHAR(128)
+);
+
+CREATE INDEX "IX_ARP_ON_ACTIVE_RULE_ID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddUuidColumnToActiveRuleParametersTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/AddUuidColumnToActiveRuleParametersTest/schema.sql
new file mode 100644 (file)
index 0000000..8366c74
--- /dev/null
@@ -0,0 +1,9 @@
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "ACTIVE_RULE_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_ID" INTEGER NOT NULL,
+    "VALUE" VARCHAR(4000),
+    "RULES_PARAMETER_KEY" VARCHAR(128)
+);
+ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "PK_ACTIVE_RULE_PARAMETERS" PRIMARY KEY("ID");
+CREATE INDEX "IX_ARP_ON_ACTIVE_RULE_ID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropIdColumnOfActiveRuleParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropIdColumnOfActiveRuleParametersTableTest/schema.sql
new file mode 100644 (file)
index 0000000..c95e98d
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "ACTIVE_RULE_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_ID" INTEGER NOT NULL,
+    "VALUE" VARCHAR(4000),
+    "RULES_PARAMETER_KEY" VARCHAR(128)
+);
+ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "PK_ACTIVE_RULE_PARAMETERS" PRIMARY KEY("UUID");
+CREATE INDEX "IX_ARP_ON_ACTIVE_RULE_ID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest/schema.sql
new file mode 100644 (file)
index 0000000..88efe9d
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "ACTIVE_RULE_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_ID" INTEGER NOT NULL,
+    "VALUE" VARCHAR(4000),
+    "RULES_PARAMETER_KEY" VARCHAR(128)
+);
+ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "PK_ACTIVE_RULE_PARAMETERS" PRIMARY KEY("ID");
+CREATE INDEX "IX_ARP_ON_ACTIVE_RULE_ID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/MakeActiveRuleParametersUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/MakeActiveRuleParametersUuidColumnNotNullableTest/schema.sql
new file mode 100644 (file)
index 0000000..e3fb5b7
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40),
+    "ACTIVE_RULE_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_ID" INTEGER NOT NULL,
+    "VALUE" VARCHAR(4000),
+    "RULES_PARAMETER_KEY" VARCHAR(128)
+);
+ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "PK_ACTIVE_RULE_PARAMETERS" PRIMARY KEY("ID");
+CREATE INDEX "IX_ARP_ON_ACTIVE_RULE_ID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/PopulateActiveRuleParametersUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activeruleparameters/PopulateActiveRuleParametersUuidTest/schema.sql
new file mode 100644 (file)
index 0000000..e3fb5b7
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40),
+    "ACTIVE_RULE_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_ID" INTEGER NOT NULL,
+    "VALUE" VARCHAR(4000),
+    "RULES_PARAMETER_KEY" VARCHAR(128)
+);
+ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "PK_ACTIVE_RULE_PARAMETERS" PRIMARY KEY("ID");
+CREATE INDEX "IX_ARP_ON_ACTIVE_RULE_ID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_ID");
index d788f642ba5e5b1147d383b2c74f0736ae4a0bfc..4f669fc61982951ebae5032a2e7f01d9bdf0b9c4 100644 (file)
@@ -321,7 +321,7 @@ public class RuleUpdater {
     @Override
     public void accept(@Nonnull ActiveRuleParamDto activeRuleParamDto) {
       if (activeRuleParamDto.getKey().equals(key)) {
-        dbClient.activeRuleDao().deleteParamById(dbSession, activeRuleParamDto.getId());
+        dbClient.activeRuleDao().deleteParamById(dbSession, activeRuleParamDto.getUuid());
       }
     }
   }