Browse Source

SONAR-13221 change PK to uuid of RULES_PARAMETERS table

* change rules_parameter_id of ACTIVE_RULE_PARAMETERS table to rules_parameter_uuid
tags/8.4.0.35506
Jacek 4 years ago
parent
commit
65e12a8ca0
45 changed files with 1239 additions and 44 deletions
  1. 1
    1
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java
  2. 7
    7
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleParamDto.java
  3. 12
    3
      server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java
  4. 2
    2
      server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java
  5. 5
    5
      server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java
  6. 3
    3
      server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml
  7. 9
    7
      server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
  8. 5
    5
      server/sonar-db-dao/src/schema/schema-sq.ddl
  9. 3
    3
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java
  10. 3
    3
      server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java
  11. 26
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
  12. 38
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTable.java
  13. 31
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParameters.java
  14. 31
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTable.java
  15. 32
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTable.java
  16. 31
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullable.java
  17. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuid.java
  18. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParameters.java
  19. 37
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTable.java
  20. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullable.java
  21. 49
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuid.java
  22. 51
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTableTest.java
  23. 67
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParametersTest.java
  24. 51
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTableTest.java
  25. 56
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest.java
  26. 43
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullableTest.java
  27. 82
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuidTest.java
  28. 66
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParametersTest.java
  29. 51
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTableTest.java
  30. 43
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullableTest.java
  31. 127
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuidTest.java
  32. 11
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTableTest/schema.sql
  33. 11
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParametersTest/schema.sql
  34. 12
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTableTest/schema.sql
  35. 12
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest/schema.sql
  36. 12
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullableTest/schema.sql
  37. 12
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuidTest/schema.sql
  38. 9
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParametersTest/schema.sql
  39. 10
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTableTest/schema.sql
  40. 10
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullableTest/schema.sql
  41. 23
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuidTest/schema.sql
  42. 1
    1
      server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java
  43. 2
    2
      server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java
  44. 1
    1
      server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java
  45. 1
    1
      server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java

+ 1
- 1
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java View 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());

+ 7
- 7
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleParamDto.java View 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) {

+ 12
- 3
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java View 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) {

+ 2
- 2
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java View 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();


+ 5
- 5
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java View 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;
}


+ 3
- 3
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml View File

@@ -198,7 +198,7 @@
<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>
@@ -207,13 +207,13 @@
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}
)

+ 9
- 7
server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml View File

@@ -461,15 +461,15 @@
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",
@@ -512,15 +512,16 @@
</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,
@@ -528,6 +529,7 @@
description
)
values (
#{uuid,jdbcType=VARCHAR},
#{ruleId,jdbcType=INTEGER},
#{name,jdbcType=VARCHAR},
#{type,jdbcType=VARCHAR},
@@ -542,7 +544,7 @@
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">

+ 5
- 5
server/sonar-db-dao/src/schema/schema-sq.ddl View 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");


+ 3
- 3
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java View 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"));
}


+ 3
- 3
server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java View 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();
}

+ 26
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java View 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)

;
}
}

+ 38
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTable.java View File

@@ -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());
}

}

+ 31
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParameters.java View File

@@ -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);
}
}

+ 31
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTable.java View File

@@ -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);
}
}

+ 32
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTable.java View File

@@ -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);
}
}

+ 31
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullable.java View File

@@ -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);
}
}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuid.java View File

@@ -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;
});
}
}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParameters.java View File

@@ -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());
}
}

+ 37
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTable.java View File

@@ -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());
}
}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullable.java View File

@@ -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());
}
}

+ 49
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuid.java View File

@@ -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;
});
}
}

+ 51
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTableTest.java View File

@@ -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);
}

}

+ 67
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParametersTest.java View File

@@ -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());
}
}

+ 51
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTableTest.java View File

@@ -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);
}

}

+ 56
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest.java View File

@@ -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);
}

}

+ 43
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullableTest.java View File

@@ -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);
}
}

+ 82
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuidTest.java View File

@@ -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());
}

}

+ 66
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParametersTest.java View File

@@ -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);
}
}

+ 51
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTableTest.java View File

@@ -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);
}

}

+ 43
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullableTest.java View File

@@ -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);
}
}

+ 127
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuidTest.java View File

@@ -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;
}

}

+ 11
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTableTest/schema.sql View File

@@ -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");

+ 11
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/AddUuidColumnToRulesParametersTest/schema.sql View File

@@ -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");

+ 12
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropIdColumnOfRulesParametersTableTest/schema.sql View File

@@ -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");

+ 12
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest/schema.sql View File

@@ -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");

+ 12
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/MakeRulesParametersUuidColumnNotNullableTest/schema.sql View File

@@ -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");

+ 12
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/PopulateRulesParametersUuidTest/schema.sql View File

@@ -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");

+ 9
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/AddRulesParameterUuidColumnToActiveRuleParametersTest/schema.sql View File

@@ -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");

+ 10
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/DropRulesParameterIdColumnOfActiveRuleParametersTableTest/schema.sql View File

@@ -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");

+ 10
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/MakeActiveRuleParametersRulesParameterUuidColumnNotNullableTest/schema.sql View File

@@ -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");

+ 23
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesparameters/fk/PopulateActiveRuleParametersRulesParameterUuidTest/schema.sql View File

@@ -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");

+ 1
- 1
server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java View 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);

+ 2
- 2
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java View 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);

+ 1
- 1
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java View 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();

+ 1
- 1
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java View 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();

Loading…
Cancel
Save