]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13221 change PK to uuid of RULES_PARAMETERS table
authorJacek <jacek.poreda@sonarsource.com>
Fri, 17 Apr 2020 14:39:24 +0000 (16:39 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 25 May 2020 20:05:20 +0000 (20:05 +0000)
* change rules_parameter_id of ACTIVE_RULE_PARAMETERS table to rules_parameter_uuid

45 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/ActiveRuleParamDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.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-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.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/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParameters.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuid.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParameters.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuid.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParametersTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuidTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParametersTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuidTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParametersTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuidTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParametersTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuidTest/schema.sql [new file with mode: 0644]
server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java

index 68e156594d084c680f9f2bce79a54a43502f7f90..bea2f1a725a2c75378048b6a7917ae882fd0c8f2 100644 (file)
@@ -153,7 +153,7 @@ public class ActiveRuleDao implements Dao {
   public ActiveRuleParamDto insertParam(DbSession dbSession, ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam) {
     checkArgument(activeRule.getUuid() != null, ACTIVE_RULE_IS_NOT_PERSISTED);
     checkArgument(activeRuleParam.getUuid() == null, ACTIVE_RULE_PARAM_IS_ALREADY_PERSISTED);
-    Preconditions.checkNotNull(activeRuleParam.getRulesParameterId(), RULE_PARAM_IS_NOT_PERSISTED);
+    Preconditions.checkNotNull(activeRuleParam.getRulesParameterUuid(), RULE_PARAM_IS_NOT_PERSISTED);
 
     activeRuleParam.setActiveRuleUuid(activeRule.getUuid());
     activeRuleParam.setUuid(uuidFactory.create());
index c42c89923a4d61b263a383ab759d41f03a7e31a5..ebfcda04ff824b7d0182003b057833ff40f0fa20 100644 (file)
@@ -31,7 +31,7 @@ public class ActiveRuleParamDto {
 
   private String uuid;
   private String activeRuleUuid;
-  private Integer rulesParameterId;
+  private String rulesParameterUuid;
   private String kee;
   private String value;
 
@@ -53,13 +53,13 @@ public class ActiveRuleParamDto {
     return this;
   }
 
-  public Integer getRulesParameterId() {
-    return rulesParameterId;
+  public String getRulesParameterUuid() {
+    return rulesParameterUuid;
   }
 
   // TODO set private or drop
-  public ActiveRuleParamDto setRulesParameterId(Integer rulesParameterId) {
-    this.rulesParameterId = rulesParameterId;
+  public ActiveRuleParamDto setRulesParameterUuid(String rulesParameterUuid) {
+    this.rulesParameterUuid = rulesParameterUuid;
     return this;
   }
 
@@ -87,10 +87,10 @@ public class ActiveRuleParamDto {
   }
 
   public static ActiveRuleParamDto createFor(RuleParamDto param) {
-    Preconditions.checkArgument(param.getId() != null, "Parameter is not persisted");
+    Preconditions.checkArgument(param.getUuid() != null, "Parameter is not persisted");
     return new ActiveRuleParamDto()
       .setKey(param.getName())
-      .setRulesParameterId(param.getId());
+      .setRulesParameterUuid(param.getUuid());
   }
 
   public static Map<String, ActiveRuleParamDto> groupByKey(Collection<ActiveRuleParamDto> params) {
index 2139c8670a7f8b85a87257f959913bad353f30c8..7fa6d8a3554735d619a8fc589e8e2106b894e5e0 100644 (file)
@@ -28,6 +28,7 @@ import javax.annotation.Nullable;
 import org.apache.ibatis.session.ResultHandler;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.RuleQuery;
+import org.sonar.core.util.UuidFactory;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
 import org.sonar.db.RowNotFoundException;
@@ -43,6 +44,12 @@ import static org.sonar.db.DatabaseUtils.executeLargeUpdates;
 
 public class RuleDao implements Dao {
 
+  private final UuidFactory uuidFactory;
+
+  public RuleDao(UuidFactory uuidFactory) {
+    this.uuidFactory = uuidFactory;
+  }
+
   public Optional<RuleDto> selectByKey(DbSession session, String organizationUuid, RuleKey key) {
     RuleDto res = mapper(session).selectByKey(organizationUuid, key);
     ensureOrganizationIsSet(organizationUuid, res);
@@ -235,19 +242,21 @@ public class RuleDao implements Dao {
   public void insertRuleParam(DbSession session, RuleDefinitionDto rule, RuleParamDto param) {
     checkNotNull(rule.getId(), "Rule id must be set");
     param.setRuleId(rule.getId());
+
+    param.setUuid(uuidFactory.create());
     mapper(session).insertParameter(param);
   }
 
   public RuleParamDto updateRuleParam(DbSession session, RuleDefinitionDto rule, RuleParamDto param) {
     checkNotNull(rule.getId(), "Rule id must be set");
-    checkNotNull(param.getId(), "Rule parameter is not yet persisted must be set");
+    checkNotNull(param.getUuid(), "Rule parameter is not yet persisted must be set");
     param.setRuleId(rule.getId());
     mapper(session).updateParameter(param);
     return param;
   }
 
-  public void deleteRuleParam(DbSession session, int ruleParameterId) {
-    mapper(session).deleteParameter(ruleParameterId);
+  public void deleteRuleParam(DbSession session, String ruleParameterUuid) {
+    mapper(session).deleteParameter(ruleParameterUuid);
   }
 
   public Set<DeprecatedRuleKeyDto> selectAllDeprecatedRuleKeys(DbSession session) {
index 308a422e4a7de48d9038a4450c610c6578adfc92..8c26caa5e108e1c5a68588d5ec7413add3e78c46 100644 (file)
@@ -23,9 +23,9 @@ import java.util.List;
 import java.util.Set;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.session.ResultHandler;
-import org.sonar.db.es.RuleExtensionId;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.RuleQuery;
+import org.sonar.db.es.RuleExtensionId;
 
 public interface RuleMapper {
 
@@ -85,7 +85,7 @@ public interface RuleMapper {
 
   void updateParameter(RuleParamDto param);
 
-  void deleteParameter(Integer paramId);
+  void deleteParameter(String paramUuid);
 
   Set<DeprecatedRuleKeyDto> selectAllDeprecatedRuleKeys();
 
index 7d35788103ed4861f8d7e55ce19c210334179680..d30ad25377eff8d4380e180b5bff241b854fcae0 100644 (file)
@@ -28,19 +28,19 @@ import static com.google.common.base.Preconditions.checkArgument;
 
 public class RuleParamDto {
 
-  private Integer id;
+  private String uuid;
   private Integer ruleId;
   private String name;
   private String type;
   private String defaultValue;
   private String description;
 
-  public Integer getId() {
-    return id;
+  public String getUuid() {
+    return uuid;
   }
 
-  public RuleParamDto setId(Integer id) {
-    this.id = id;
+  public RuleParamDto setUuid(String uuid) {
+    this.uuid = uuid;
     return this;
   }
 
index 7649914ce453851aa24e9182ca9d9d2acbb5e1c1..26e013c0bfb35183bc109496d4e9725381690fdc 100644 (file)
   <sql id="activeRuleParamColumns">
     p.uuid,
     p.active_rule_uuid as activeRuleUuid,
-    p.rules_parameter_id as rulesParameterId,
+    p.rules_parameter_uuid as rulesParameterUuid,
     p.rules_parameter_key as kee,
     p.value as value
   </sql>
     insert into active_rule_parameters (
       uuid,
       active_rule_uuid,
-      rules_parameter_id,
+      rules_parameter_uuid,
       rules_parameter_key,
       value
     ) values (
       #{uuid, jdbcType=VARCHAR},
       #{activeRuleUuid, jdbcType=VARCHAR},
-      #{rulesParameterId, jdbcType=BIGINT},
+      #{rulesParameterUuid, jdbcType=BIGINT},
       #{key, jdbcType=VARCHAR},
       #{value, jdbcType=VARCHAR}
     )
index 1c976aacead866d6536a0103135ebbfcdb0721ab..b55391d4cbc6ba6e74822a4f77077abdfb27c3bf 100644 (file)
       and organization_uuid=#{organizationUuid,jdbcType=VARCHAR}
   </update>
 
-  <delete id="deleteParams" parameterType="Integer">
+  <delete id="deleteParams" parameterType="String">
     delete from
       active_rule_parameters
     where
-      rules_parameter_id=#{id,jdbcType=INTEGER}
+      rules_parameter_uuid=#{uuid,jdbcType=VARCHAR}
   </delete>
 
   <sql id="paramColumns">
-    p.id as "id",
+    p.uuid as "uuid",
     p.rule_id as "ruleId",
     p.name as "name",
     p.param_type as "type",
       </foreach>
   </select>
 
-  <delete id="deleteParameter" parameterType="Integer">
+  <delete id="deleteParameter" parameterType="String">
     delete from
       rules_parameters
     where
-      id=#{id,jdbcType=INTEGER}
+      uuid=#{uuid,jdbcType=INTEGER}
   </delete>
 
-  <insert id="insertParameter" parameterType="RuleParam" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insertParameter" parameterType="RuleParam" useGeneratedKeys="false">
     insert into rules_parameters (
+      uuid,
       rule_id,
       name,
       param_type,
       description
     )
     values (
+      #{uuid,jdbcType=VARCHAR},
       #{ruleId,jdbcType=INTEGER},
       #{name,jdbcType=VARCHAR},
       #{type,jdbcType=VARCHAR},
       default_value=#{defaultValue,jdbcType=VARCHAR},
       description=#{description,jdbcType=VARCHAR}
     where
-      id=#{id,jdbcType=INTEGER}
+      uuid=#{uuid,jdbcType=VARCHAR}
   </update>
 
   <select id="selectAllDeprecatedRuleKeys" resultType="org.sonar.db.rule.DeprecatedRuleKeyDto">
index 98df38e29737afcd528b008f9fc89a885bb0f5f0..bd57c4aec5df814b9c6e9b9bbf3dced5a7e846e0 100644 (file)
@@ -14,11 +14,11 @@ CREATE TABLE "SCHEMA_MIGRATIONS"(
 );
 
 CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
-    "RULES_PARAMETER_ID" INTEGER NOT NULL,
     "VALUE" VARCHAR(4000),
     "RULES_PARAMETER_KEY" VARCHAR(128),
     "UUID" VARCHAR(40) NOT NULL,
-    "ACTIVE_RULE_UUID" VARCHAR(40) NOT NULL
+    "ACTIVE_RULE_UUID" VARCHAR(40) NOT NULL,
+    "RULES_PARAMETER_UUID" VARCHAR(40) NOT NULL
 );
 ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "PK_ACTIVE_RULE_PARAMETERS" PRIMARY KEY("UUID");
 CREATE INDEX "ARP_ACTIVE_RULE_UUID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_UUID");
@@ -852,14 +852,14 @@ CREATE TABLE "RULES_METADATA"(
 ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_ID", "ORGANIZATION_UUID");
 
 CREATE TABLE "RULES_PARAMETERS"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
     "RULE_ID" INTEGER NOT NULL,
     "NAME" VARCHAR(128) NOT NULL,
     "DESCRIPTION" VARCHAR(4000),
     "PARAM_TYPE" VARCHAR(512) NOT NULL,
-    "DEFAULT_VALUE" VARCHAR(4000)
+    "DEFAULT_VALUE" VARCHAR(4000),
+    "UUID" VARCHAR(40) NOT NULL
 );
-ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("ID");
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
 CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
 CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
 
index 418fc1b8efb8fa5b20046a2ddd3db0c084955357..738d46df97621164f6d747988937d7b5de01114f 100644 (file)
@@ -465,7 +465,7 @@ public class ActiveRuleDaoTest {
       .matches(p -> Objects.equals(p.getUuid(), activeRuleParam.getUuid()))
       .matches(p -> p.getKey().equals(activeRuleParam.getKey()))
       .matches(p -> p.getActiveRuleUuid().equals(activeRule.getUuid()))
-      .matches(p -> p.getRulesParameterId().equals(rule1Param1.getId()))
+      .matches(p -> p.getRulesParameterUuid().equals(rule1Param1.getUuid()))
       .matches(p -> p.getValue().equals("foo"));
   }
 
@@ -496,7 +496,7 @@ public class ActiveRuleDaoTest {
 
     underTest.insertParam(dbSession,
       createFor(profile1, rule1).setUuid("uuid"),
-      ActiveRuleParamDto.createFor(rule1Param1).setValue("activeValue1").setRulesParameterId(null));
+      ActiveRuleParamDto.createFor(rule1Param1).setValue("activeValue1").setRulesParameterUuid(null));
   }
 
   @Test
@@ -514,7 +514,7 @@ public class ActiveRuleDaoTest {
       .matches(p -> Objects.equals(p.getUuid(), activeRuleParam.getUuid()))
       .matches(p -> p.getKey().equals(activeRuleParam.getKey()))
       .matches(p -> p.getActiveRuleUuid().equals(activeRule.getUuid()))
-      .matches(p -> p.getRulesParameterId().equals(rule1Param1.getId()))
+      .matches(p -> p.getRulesParameterUuid().equals(rule1Param1.getUuid()))
       .matches(p -> p.getValue().equals("bar"));
   }
 
index 5fc68e9ab2d2024190a4897ce8206e3b09b399d2..e93569a7d1e60f22c99ec69e9807ef046fe1d7fa 100644 (file)
@@ -831,7 +831,7 @@ public class RuleDaoTest {
 
     assertThat(ruleDtos.size()).isEqualTo(1);
     RuleParamDto ruleDto = ruleDtos.get(0);
-    assertThat(ruleDto.getId()).isEqualTo(ruleParam.getId());
+    assertThat(ruleDto.getUuid()).isEqualTo(ruleParam.getUuid());
     assertThat(ruleDto.getName()).isEqualTo(ruleParam.getName());
     assertThat(ruleDto.getDescription()).isEqualTo(ruleParam.getDescription());
     assertThat(ruleDto.getType()).isEqualTo(ruleParam.getType());
@@ -899,7 +899,7 @@ public class RuleDaoTest {
     List<RuleParamDto> params = underTest.selectRuleParamsByRuleKey(db.getSession(), rule.getKey());
     assertThat(params).hasSize(1);
     RuleParamDto param = new RuleParamDto()
-      .setId(ruleParam.getId())
+      .setUuid(ruleParam.getUuid())
       .setRuleId(rule.getId())
       // Name will not be updated
       .setName("format")
@@ -920,7 +920,7 @@ public class RuleDaoTest {
     RuleParamDto ruleParam = db.rules().insertRuleParam(rule);
     assertThat(underTest.selectRuleParamsByRuleKey(db.getSession(), rule.getKey())).hasSize(1);
 
-    underTest.deleteRuleParam(db.getSession(), ruleParam.getId());
+    underTest.deleteRuleParam(db.getSession(), ruleParam.getUuid());
 
     assertThat(underTest.selectRuleParamsByRuleKey(db.getSession(), rule.getKey())).isEmpty();
   }
index 4e028bead2db7f6b14dc10345319a35438ae93d0..d2e45c4e5be6b6b6f875c729839ae00c65a51797 100644 (file)
@@ -115,6 +115,16 @@ import org.sonar.server.platform.db.migration.version.v83.projectmeasures.DropId
 import org.sonar.server.platform.db.migration.version.v83.projectmeasures.DropPrimaryKeyOnIdColumnOfProjectMeasuresTable;
 import org.sonar.server.platform.db.migration.version.v83.projectmeasures.MakeProjectMeasuresUuidColumnNotNullable;
 import org.sonar.server.platform.db.migration.version.v83.projectmeasures.PopulateProjectMeasureUuid;
+import org.sonar.server.platform.db.migration.version.v83.rulesparameters.AddPrimaryKeyOnUuidColumnOfRulesParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.rulesparameters.AddUuidColumnToRulesParameters;
+import org.sonar.server.platform.db.migration.version.v83.rulesparameters.DropIdColumnOfRulesParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.rulesparameters.DropPrimaryKeyOnIdColumnOfRulesParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.rulesparameters.MakeRulesParametersUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.rulesparameters.PopulateRulesParametersUuid;
+import org.sonar.server.platform.db.migration.version.v83.rulesparameters.fk.AddRulesParameterUuidColumnToActiveRuleParameters;
+import org.sonar.server.platform.db.migration.version.v83.rulesparameters.fk.DropRulesParameterIdColumnOfActiveRuleParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.rulesparameters.fk.MakeActiveRuleParametersRulesParameterUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.rulesparameters.fk.PopulateActiveRuleParametersRulesParameterUuid;
 import org.sonar.server.platform.db.migration.version.v83.projectqprofiles.AddPrimaryKeyOnUuidColumnOfProjectQProfilesTable;
 import org.sonar.server.platform.db.migration.version.v83.projectqprofiles.AddUuidColumnToProjectQProfilesTable;
 import org.sonar.server.platform.db.migration.version.v83.projectqprofiles.DropIdColumnOfProjectQProfilesTable;
@@ -330,6 +340,22 @@ public class DbVersion83 implements DbVersion {
       .add(3516, "Drop column 'ID' of 'ACTIVE_RULES' table", DropIdColumnOfActiveRulesTable.class)
       .add(3517, "Drop column 'active_rule_id' of 'ACTIVE_RULE_PARAMETERS' table", DropActiveRuleIdColumnOfActiveRuleParametersTable.class)
 
+      // Migration on RULES_PARAMETERS table - populate uuid column
+      .add(3518, "Add 'uuid' column for 'RULES_PARAMETERS'", AddUuidColumnToRulesParameters.class)
+      .add(3519, "Populate 'uuid' column for 'RULES_PARAMETERS'", PopulateRulesParametersUuid.class)
+      .add(3520, "Make 'uuid' column not nullable for 'RULES_PARAMETERS'", MakeRulesParametersUuidColumnNotNullable.class)
+
+      // Migration of ACTIVE_RULE_PARAMS FK to RULES_PARAMETERS, switch from ruleParamId to ruleParamUuid
+      .add(3521, "Add 'rules_parameter_uuid' column for 'ACTIVE_RULE_PARAMS' table", AddRulesParameterUuidColumnToActiveRuleParameters.class)
+      .add(3522, "Populate 'rules_parameter_uuid' column for 'ACTIVE_RULE_PARAMS' table", PopulateActiveRuleParametersRulesParameterUuid.class)
+      .add(3523, "Make 'rules_parameter_uuid' column not nullable for 'ACTIVE_RULE_PARAMS' table", MakeActiveRuleParametersRulesParameterUuidColumnNotNullable.class)
+      .add(3524, "Drop column 'rules_parameter_id' of 'ACTIVE_RULE_PARAMS' table", DropRulesParameterIdColumnOfActiveRuleParametersTable.class)
+
+      // Migration on RULES_PARAMETERS table change PK
+      .add(3525, "Drop primary key on 'ID' column of 'RULES_PARAMETERS' table", DropPrimaryKeyOnIdColumnOfRulesParametersTable.class)
+      .add(3526, "Add primary key on 'UUID' column of 'RULES_PARAMETERS' table", AddPrimaryKeyOnUuidColumnOfRulesParametersTable.class)
+      .add(3527, "Drop column 'ID' of 'RULES_PARAMETERS' table", DropIdColumnOfRulesParametersTable.class)
+
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTable.java
new file mode 100644 (file)
index 0000000..2b32201
--- /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.rulesparameters;
+
+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 AddPrimaryKeyOnUuidColumnOfRulesParametersTable extends DdlChange {
+
+  public AddPrimaryKeyOnUuidColumnOfRulesParametersTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddPrimaryKeyBuilder("rules_parameters", "uuid").build());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParameters.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParameters.java
new file mode 100644 (file)
index 0000000..7bc9377
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.rulesparameters;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable;
+
+public class AddUuidColumnToRulesParameters extends AddUuidColumnToTable {
+  private static final String TABLE_NAME = "rules_parameters";
+
+  public AddUuidColumnToRulesParameters(Database db) {
+    super(db, TABLE_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTable.java
new file mode 100644 (file)
index 0000000..3a16921
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.rulesparameters;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.DropIdColumn;
+
+public class DropIdColumnOfRulesParametersTable extends DropIdColumn {
+  private static final String TABLE_NAME = "rules_parameters";
+
+  public DropIdColumnOfRulesParametersTable(Database db) {
+    super(db, TABLE_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTable.java
new file mode 100644 (file)
index 0000000..fde1307
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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.rulesparameters;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.DropPrimaryKeyOnIdColumn;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnIdColumnOfRulesParametersTable extends DropPrimaryKeyOnIdColumn {
+  private static final String TABLE_NAME = "rules_parameters";
+
+  public DropPrimaryKeyOnIdColumnOfRulesParametersTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+    super(db, dropPrimaryKeySqlGenerator, TABLE_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullable.java
new file mode 100644 (file)
index 0000000..86b023e
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.rulesparameters;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.MakeUuidColumnNotNullable;
+
+public class MakeRulesParametersUuidColumnNotNullable extends MakeUuidColumnNotNullable {
+  private static final String TABLE_NAME = "rules_parameters";
+
+  public MakeRulesParametersUuidColumnNotNullable(Database db) {
+    super(db, TABLE_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuid.java
new file mode 100644 (file)
index 0000000..c86a5d0
--- /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.rulesparameters;
+
+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 PopulateRulesParametersUuid extends DataChange {
+
+  private final UuidFactory uuidFactory;
+
+  public PopulateRulesParametersUuid(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 rules_parameters where uuid is null");
+    massUpdate.update("update rules_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/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParameters.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParameters.java
new file mode 100644 (file)
index 0000000..a38d87c
--- /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.rulesparameters.fk;
+
+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 AddRulesParameterUuidColumnToActiveRuleParameters extends DdlChange {
+  private static final String TABLE = "active_rule_parameters";
+
+  private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+    .setColumnName("rules_parameter_uuid")
+    .setIsNullable(true)
+    .setDefaultValue(null)
+    .setLimit(VarcharColumnDef.UUID_SIZE)
+    .build();
+
+  public AddRulesParameterUuidColumnToActiveRuleParameters(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/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTable.java
new file mode 100644 (file)
index 0000000..aaad275
--- /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.rulesparameters.fk;
+
+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 DropRulesParameterIdColumnOfActiveRuleParametersTable extends DdlChange {
+
+  public DropRulesParameterIdColumnOfActiveRuleParametersTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new DropColumnsBuilder(getDialect(), "active_rule_parameters", "rules_parameter_id").build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullable.java
new file mode 100644 (file)
index 0000000..bd236b9
--- /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.rulesparameters.fk;
+
+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 MakeActiveRuleParametersRulesParameterUuidColumnNotNullable extends DdlChange {
+  private static final String TABLE = "active_rule_parameters";
+
+  private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+    .setColumnName("rules_parameter_uuid")
+    .setIsNullable(false)
+    .setDefaultValue(null)
+    .setLimit(VarcharColumnDef.UUID_SIZE)
+    .build();
+
+  public MakeActiveRuleParametersRulesParameterUuidColumnNotNullable(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/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuid.java
new file mode 100644 (file)
index 0000000..62ae81a
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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.rulesparameters.fk;
+
+import java.sql.SQLException;
+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 PopulateActiveRuleParametersRulesParameterUuid extends DataChange {
+
+  public PopulateActiveRuleParametersRulesParameterUuid(Database db) {
+    super(db);
+  }
+
+  @Override
+  protected void execute(Context context) throws SQLException {
+    MassUpdate massUpdate = context.prepareMassUpdate();
+
+    massUpdate.select("select arp.uuid, rp.uuid " +
+      "from active_rule_parameters arp " +
+      "join rules_parameters rp on arp.rules_parameter_id = rp.id " +
+      "where arp.rules_parameter_uuid is null");
+    massUpdate.update("update active_rule_parameters set rules_parameter_uuid = ? where uuid = ?");
+
+    massUpdate.execute((row, update) -> {
+      update.setString(1, row.getString(2));
+      update.setString(2, row.getString(1));
+      return true;
+    });
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTableTest.java
new file mode 100644 (file)
index 0000000..5b8f6d6
--- /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.rulesparameters;
+
+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 AddPrimaryKeyOnUuidColumnOfRulesParametersTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfRulesParametersTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new AddPrimaryKeyOnUuidColumnOfRulesParametersTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertPrimaryKey("rules_parameters", "pk_rules_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/rulesparameters/AddUuidColumnToRulesParametersTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParametersTest.java
new file mode 100644 (file)
index 0000000..ce27de8
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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.rulesparameters;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+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.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddUuidColumnToRulesParametersTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToRulesParametersTest.class, "schema.sql");
+
+  private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+
+  private DdlChange underTest = new AddUuidColumnToRulesParameters(db.database());
+
+  @Before
+  public void setup() {
+    insertRuleParameter(1L);
+    insertRuleParameter(2L);
+    insertRuleParameter(3L);
+  }
+
+  @Test
+  public void add_uuid_column_to_project_measures() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("rules_parameters", "uuid", Types.VARCHAR, 40, true);
+
+    assertThat(db.countSql("select count(id) from rules_parameters"))
+      .isEqualTo(3);
+  }
+
+  private void insertRuleParameter(Long id) {
+    db.executeInsert("rules_parameters",
+      "id", id,
+      "rule_id", id + 100,
+      "name", uuidFactory.create(),
+      "param_type", uuidFactory.create());
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTableTest.java
new file mode 100644 (file)
index 0000000..4d39980
--- /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.rulesparameters;
+
+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 DropIdColumnOfRulesParametersTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfRulesParametersTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new DropIdColumnOfRulesParametersTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDoesNotExist("rules_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/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest.java
new file mode 100644 (file)
index 0000000..d07fa61
--- /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.rulesparameters;
+
+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.SqlHelper;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropPrimaryKeyOnIdColumnOfRulesParametersTableTest {
+
+  private static final String TABLE_NAME = "rules_parameters";
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesParametersTableTest.class, "schema.sql");
+
+  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+
+  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesParametersTable(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/rulesparameters/MakeRulesParametersUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullableTest.java
new file mode 100644 (file)
index 0000000..d2f29cf
--- /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.rulesparameters;
+
+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 MakeRulesParametersUuidColumnNotNullableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(MakeRulesParametersUuidColumnNotNullableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new MakeRulesParametersUuidColumnNotNullable(db.database());
+
+  @Test
+  public void uuid_column_is_not_null() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("rules_parameters", "uuid", VARCHAR, null, false);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuidTest.java
new file mode 100644 (file)
index 0000000..0da6eba
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * 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.rulesparameters;
+
+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 PopulateRulesParametersUuidTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(PopulateRulesParametersUuidTest.class, "schema.sql");
+
+  private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+  private DataChange underTest = new PopulateRulesParametersUuid(db.database(), uuidFactory);
+
+  @Test
+  public void populate_uuids_and_created_at() throws SQLException {
+    insertRuleParameter(1L);
+    insertRuleParameter(2L);
+    insertRuleParameter(3L);
+
+    underTest.execute();
+
+    verifyUuidsAreNotNull();
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    insertRuleParameter(1L);
+    insertRuleParameter(2L);
+    insertRuleParameter(3L);
+
+    underTest.execute();
+    // re-entrant
+    underTest.execute();
+
+    verifyUuidsAreNotNull();
+  }
+
+  private void verifyUuidsAreNotNull() {
+    assertThat(db.select("select uuid from rules_parameters")
+      .stream()
+      .map(row -> row.get("UUID"))
+      .filter(Objects::isNull)
+      .collect(Collectors.toList())).isEmpty();
+  }
+
+  private void insertRuleParameter(Long id) {
+    db.executeInsert("rules_parameters",
+      "id", id,
+      "rule_id", id + 100,
+      "name", uuidFactory.create(),
+      "param_type", uuidFactory.create());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParametersTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParametersTest.java
new file mode 100644 (file)
index 0000000..5303f2f
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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.rulesparameters.fk;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+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.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddRulesParameterUuidColumnToActiveRuleParametersTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddRulesParameterUuidColumnToActiveRuleParametersTest.class, "schema.sql");
+
+  private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+
+  private DdlChange underTest = new AddRulesParameterUuidColumnToActiveRuleParameters(db.database());
+
+  @Before
+  public void setup() {
+    insertActiveRuleParameter(uuidFactory.create(), 1L, 4L);
+    insertActiveRuleParameter(uuidFactory.create(), 2L, 5L);
+    insertActiveRuleParameter(uuidFactory.create(), 3L, 6L);
+  }
+
+  @Test
+  public void add_rules_parameter_uuid_column_to_active_rule_parameters() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("active_rule_parameters", "rules_parameter_uuid", Types.VARCHAR, 40, true);
+
+    assertThat(db.countRowsOfTable("active_rule_parameters"))
+      .isEqualTo(3);
+  }
+
+  private void insertActiveRuleParameter(String uuid, Long ruleId, Long rulesParameterId) {
+    db.executeInsert("active_rule_parameters",
+      "uuid", uuid,
+      "active_rule_id", ruleId,
+      "rules_parameter_id", rulesParameterId);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTableTest.java
new file mode 100644 (file)
index 0000000..da25ea3
--- /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.rulesparameters.fk;
+
+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 DropRulesParameterIdColumnOfActiveRuleParametersTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropRulesParameterIdColumnOfActiveRuleParametersTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new DropRulesParameterIdColumnOfActiveRuleParametersTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDoesNotExist("active_rule_parameters", "rules_parameter_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/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullableTest.java
new file mode 100644 (file)
index 0000000..b9951ff
--- /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.rulesparameters.fk;
+
+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 MakeActiveRuleParametersRulesParameterUuidColumnNotNullableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(MakeActiveRuleParametersRulesParameterUuidColumnNotNullableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new MakeActiveRuleParametersRulesParameterUuidColumnNotNullable(db.database());
+
+  @Test
+  public void uuid_column_is_not_null() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("active_rule_parameters", "rules_parameter_uuid", VARCHAR, null, false);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuidTest.java
new file mode 100644 (file)
index 0000000..f0b6c32
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * 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.rulesparameters.fk;
+
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+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 java.lang.String.format;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PopulateActiveRuleParametersRulesParameterUuidTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(PopulateActiveRuleParametersRulesParameterUuidTest.class, "schema.sql");
+
+  private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+  private DataChange underTest = new PopulateActiveRuleParametersRulesParameterUuid(db.database());
+
+  @Test
+  public void populate_rules_parameter_uuids() throws SQLException {
+    String ruleParamUuid1 = uuidFactory.create();
+    long ruleParamId1 = 1L;
+    insertRuleParameter(ruleParamId1, ruleParamUuid1, 101L);
+    String activeRuleParameter11 = insertActiveRuleParameter(101L, ruleParamId1);
+    String activeRuleParameter12 = insertActiveRuleParameter(101L, ruleParamId1);
+    String activeRuleParameter13 = insertActiveRuleParameter(101L, ruleParamId1);
+
+    String ruleParamUuid2 = uuidFactory.create();
+    long ruleParamId2 = 2L;
+    insertRuleParameter(ruleParamId2, ruleParamUuid2, 101L);
+    String activeRuleParameter21 = insertActiveRuleParameter(101L, ruleParamId2);
+    String activeRuleParameter22 = insertActiveRuleParameter(101L, ruleParamId2);
+
+    insertRuleParameter(3L, uuidFactory.create(), 101L);
+
+    underTest.execute();
+
+    assertRulesParameterUuidsAreNotNull();
+    assertThatRulesParametersUuidAreSet(ruleParamUuid1, activeRuleParameter11, activeRuleParameter12, activeRuleParameter13);
+    assertThatRulesParametersUuidAreSet(ruleParamUuid2, activeRuleParameter21, activeRuleParameter22);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    String ruleParamUuid1 = uuidFactory.create();
+    long ruleParamId1 = 1L;
+    insertRuleParameter(ruleParamId1, ruleParamUuid1, 101L);
+    String activeRuleParameter11 = insertActiveRuleParameter(101L, ruleParamId1);
+    String activeRuleParameter12 = insertActiveRuleParameter(101L, ruleParamId1);
+    String activeRuleParameter13 = insertActiveRuleParameter(101L, ruleParamId1);
+
+    underTest.execute();
+
+    String ruleParamUuid2 = uuidFactory.create();
+    long ruleParamId2 = 2L;
+    insertRuleParameter(ruleParamId2, ruleParamUuid2, 101L);
+    String activeRuleParameter21 = insertActiveRuleParameter(101L, ruleParamId2);
+    String activeRuleParameter22 = insertActiveRuleParameter(101L, ruleParamId2);
+    // re-entrant
+    underTest.execute();
+
+    assertRulesParameterUuidsAreNotNull();
+    assertThatRulesParametersUuidAreSet(ruleParamUuid1, activeRuleParameter11, activeRuleParameter12, activeRuleParameter13);
+    assertThatRulesParametersUuidAreSet(ruleParamUuid2, activeRuleParameter21, activeRuleParameter22);
+  }
+
+  private void assertThatRulesParametersUuidAreSet(String ruleParameterUuid, String... activeRuleParameters) {
+    assertThat(db.select("select rules_parameter_uuid from active_rule_parameters where uuid in ("
+      + Stream.of(activeRuleParameters).map(s -> format("'%s'", s)).collect(Collectors.joining(",")) + ")")
+      .stream()
+      .map(row -> row.get("RULES_PARAMETER_UUID"))
+      .filter(o -> !Objects.equals(o, ruleParameterUuid))
+      .collect(Collectors.toList())).isEmpty();
+  }
+
+  private void assertRulesParameterUuidsAreNotNull() {
+    assertThat(db.select("select rules_parameter_uuid from active_rule_parameters")
+      .stream()
+      .map(row -> row.get("RULES_PARAMETER_UUID"))
+      .filter(Objects::isNull)
+      .collect(Collectors.toList())).isEmpty();
+  }
+
+  private void insertRuleParameter(Long id, String uuid, Long ruleId) {
+    db.executeInsert("rules_parameters",
+      "id", id,
+      "uuid", uuid,
+      "rule_id", ruleId,
+      "name", uuidFactory.create(),
+      "param_type", uuidFactory.create());
+  }
+
+  private String insertActiveRuleParameter(Long ruleId, Long rulesParameterId) {
+    String uuid = uuidFactory.create();
+    db.executeInsert("active_rule_parameters",
+      "uuid", uuid,
+      "active_rule_id", ruleId,
+      "rules_parameter_id", rulesParameterId);
+    return uuid;
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTableTest/schema.sql
new file mode 100644 (file)
index 0000000..961a5cb
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "RULES_PARAMETERS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "RULE_ID" INTEGER NOT NULL,
+    "NAME" VARCHAR(128) NOT NULL,
+    "DESCRIPTION" VARCHAR(4000),
+    "PARAM_TYPE" VARCHAR(512) NOT NULL,
+    "DEFAULT_VALUE" VARCHAR(4000)
+);
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParametersTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParametersTest/schema.sql
new file mode 100644 (file)
index 0000000..98a62c6
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "RULES_PARAMETERS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "RULE_ID" INTEGER NOT NULL,
+    "NAME" VARCHAR(128) NOT NULL,
+    "DESCRIPTION" VARCHAR(4000),
+    "PARAM_TYPE" VARCHAR(512) NOT NULL,
+    "DEFAULT_VALUE" VARCHAR(4000)
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("ID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTableTest/schema.sql
new file mode 100644 (file)
index 0000000..60597ff
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "RULES_PARAMETERS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "RULE_ID" INTEGER NOT NULL,
+    "NAME" VARCHAR(128) NOT NULL,
+    "DESCRIPTION" VARCHAR(4000),
+    "PARAM_TYPE" VARCHAR(512) NOT NULL,
+    "DEFAULT_VALUE" VARCHAR(4000)
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest/schema.sql
new file mode 100644 (file)
index 0000000..efdec30
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "RULES_PARAMETERS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "RULE_ID" INTEGER NOT NULL,
+    "NAME" VARCHAR(128) NOT NULL,
+    "DESCRIPTION" VARCHAR(4000),
+    "PARAM_TYPE" VARCHAR(512) NOT NULL,
+    "DEFAULT_VALUE" VARCHAR(4000)
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("ID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullableTest/schema.sql
new file mode 100644 (file)
index 0000000..55efee5
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "RULES_PARAMETERS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40),
+    "RULE_ID" INTEGER NOT NULL,
+    "NAME" VARCHAR(128) NOT NULL,
+    "DESCRIPTION" VARCHAR(4000),
+    "PARAM_TYPE" VARCHAR(512) NOT NULL,
+    "DEFAULT_VALUE" VARCHAR(4000)
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("ID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuidTest/schema.sql
new file mode 100644 (file)
index 0000000..55efee5
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "RULES_PARAMETERS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40),
+    "RULE_ID" INTEGER NOT NULL,
+    "NAME" VARCHAR(128) NOT NULL,
+    "DESCRIPTION" VARCHAR(4000),
+    "PARAM_TYPE" VARCHAR(512) NOT NULL,
+    "DEFAULT_VALUE" VARCHAR(4000)
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("ID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParametersTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParametersTest/schema.sql
new file mode 100644 (file)
index 0000000..04d58e9
--- /dev/null
@@ -0,0 +1,9 @@
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+    "ACTIVE_RULE_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_ID" INTEGER NOT NULL,
+    "VALUE" VARCHAR(4000),
+    "RULES_PARAMETER_KEY" VARCHAR(128),
+    "UUID" VARCHAR(40) NOT NULL
+);
+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/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTableTest/schema.sql
new file mode 100644 (file)
index 0000000..3782982
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+    "ACTIVE_RULE_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_UUID" VARCHAR(40) NOT NULL,
+    "VALUE" VARCHAR(4000),
+    "RULES_PARAMETER_KEY" VARCHAR(128),
+    "UUID" VARCHAR(40) NOT NULL
+);
+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/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullableTest/schema.sql
new file mode 100644 (file)
index 0000000..de06e41
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+    "ACTIVE_RULE_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_UUID" VARCHAR(40),
+    "VALUE" VARCHAR(4000),
+    "RULES_PARAMETER_KEY" VARCHAR(128),
+    "UUID" VARCHAR(40) NOT NULL
+);
+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/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuidTest/schema.sql
new file mode 100644 (file)
index 0000000..0bb696c
--- /dev/null
@@ -0,0 +1,23 @@
+CREATE TABLE "RULES_PARAMETERS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "RULE_ID" INTEGER NOT NULL,
+    "NAME" VARCHAR(128) NOT NULL,
+    "DESCRIPTION" VARCHAR(4000),
+    "PARAM_TYPE" VARCHAR(512) NOT NULL,
+    "DEFAULT_VALUE" VARCHAR(4000)
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("ID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
+
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+    "ACTIVE_RULE_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_UUID" VARCHAR(40),
+    "VALUE" VARCHAR(4000),
+    "RULES_PARAMETER_KEY" VARCHAR(128),
+    "UUID" VARCHAR(40) NOT NULL
+);
+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");
index 799cd207ba7461a138c4c07c22a08f4670587848..232778f3572bfc665fbbe32594eed3bbc0665cdf 100644 (file)
@@ -554,7 +554,7 @@ public class RegisterRules implements Startable {
         profiler.start();
         dbClient.activeRuleDao().deleteParamsByRuleParamOfAllOrganizations(session, paramDto);
         profiler.stopDebug(format("Propagate deleted param with name %s to active rules of rule %s", paramDto.getName(), rule.getKey()));
-        dbClient.ruleDao().deleteRuleParam(session, paramDto.getId());
+        dbClient.ruleDao().deleteRuleParam(session, paramDto.getUuid());
       } else {
         if (mergeParam(paramDto, paramDef)) {
           dbClient.ruleDao().updateRuleParam(session, rule, paramDto);
index 7de814aad06f8d9ca896b009e63a75bf92679f3b..f365dadb1bb0d22c2ba6f0caba8805afc5c32d4f 100644 (file)
@@ -251,7 +251,7 @@ public class QProfileFactoryImplTest {
     ActiveRuleDto activeRuleDto = db.qualityProfiles().activateRule(profile, rule);
 
     ActiveRuleParamDto activeRuleParam = new ActiveRuleParamDto()
-      .setRulesParameterId(ruleParam.getId())
+      .setRulesParameterUuid(ruleParam.getUuid())
       .setKey("foo")
       .setValue("bar");
     db.getDbClient().activeRuleDao().insertParam(dbSession, activeRuleDto, activeRuleParam);
@@ -277,7 +277,7 @@ public class QProfileFactoryImplTest {
     db.getDbClient().activeRuleDao().insert(dbSession, activeRuleDto);
 
     ActiveRuleParamDto activeRuleParam = new ActiveRuleParamDto()
-      .setRulesParameterId(ruleParam.getId())
+      .setRulesParameterUuid(ruleParam.getUuid())
       .setKey("foo")
       .setValue("bar");
     db.getDbClient().activeRuleDao().insertParam(dbSession, activeRuleDto, activeRuleParam);
index 4832470ba06d33388c7bcdf151c327f208477213..adc22dd84b294e9510dfaeb253145523f7f58bb0 100644 (file)
@@ -458,7 +458,7 @@ public class RuleUpdaterTest {
     db.getDbClient().activeRuleDao().insert(dbSession, activeRuleDto);
     db.getDbClient().activeRuleDao().insertParam(dbSession, activeRuleDto, new ActiveRuleParamDto()
       .setActiveRuleUuid(activeRuleDto.getUuid())
-      .setRulesParameterId(ruleParam1.getId())
+      .setRulesParameterUuid(ruleParam1.getUuid())
       .setKey(ruleParam1.getName())
       .setValue(ruleParam1.getDefaultValue()));
     dbSession.commit();
index 50f33b8de1ef7be9158eb738d335408afe764c27..454001cb508456283a973a0de67f50ecff994b4f 100644 (file)
@@ -421,7 +421,7 @@ public class ShowActionTest {
     QProfileDto qProfile = db.qualityProfiles().insert(organization);
     ActiveRuleDto activeRule = db.qualityProfiles().activateRule(qProfile, rule);
     db.getDbClient().activeRuleDao().insertParam(db.getSession(), activeRule, new ActiveRuleParamDto()
-      .setRulesParameterId(ruleParam.getId())
+      .setRulesParameterUuid(ruleParam.getUuid())
       .setKey(ruleParam.getName())
       .setValue(".*?"));
     db.commit();