public ActiveRuleDto insert(DbSession dbSession, ActiveRuleDto item) {
checkArgument(item.getProfileId() != null, QUALITY_PROFILE_IS_NOT_PERSISTED);
checkArgument(item.getRuleId() != null, RULE_IS_NOT_PERSISTED);
- checkArgument(item.getId() == null, ACTIVE_RULE_IS_ALREADY_PERSISTED);
+ checkArgument(item.getUuid() == null, ACTIVE_RULE_IS_ALREADY_PERSISTED);
+
+ item.setUuid(uuidFactory.create());
mapper(dbSession).insert(item);
return item;
}
public ActiveRuleDto update(DbSession dbSession, ActiveRuleDto item) {
checkArgument(item.getProfileId() != null, QUALITY_PROFILE_IS_NOT_PERSISTED);
checkArgument(item.getRuleId() != null, ActiveRuleDao.RULE_IS_NOT_PERSISTED);
- checkArgument(item.getId() != null, ACTIVE_RULE_IS_NOT_PERSISTED);
+ checkArgument(item.getUuid() != null, ACTIVE_RULE_IS_NOT_PERSISTED);
mapper(dbSession).update(item);
return item;
}
public Optional<ActiveRuleDto> delete(DbSession dbSession, ActiveRuleKey key) {
Optional<ActiveRuleDto> activeRule = selectByKey(dbSession, key);
if (activeRule.isPresent()) {
- mapper(dbSession).deleteParameters(activeRule.get().getId());
- mapper(dbSession).delete(activeRule.get().getId());
+ mapper(dbSession).deleteParameters(activeRule.get().getUuid());
+ mapper(dbSession).delete(activeRule.get().getUuid());
}
return activeRule;
}
DatabaseUtils.executeLargeUpdates(rulesProfileUuids, mapper::deleteByRuleProfileUuids);
}
- public void deleteByIds(DbSession dbSession, List<Integer> activeRuleIds) {
+ public void deleteByUuids(DbSession dbSession, List<String> activeRuleUuids) {
ActiveRuleMapper mapper = mapper(dbSession);
- DatabaseUtils.executeLargeUpdates(activeRuleIds, mapper::deleteByIds);
+ DatabaseUtils.executeLargeUpdates(activeRuleUuids, mapper::deleteByUuids);
}
public void deleteParametersByRuleProfileUuids(DbSession dbSession, Collection<String> rulesProfileUuids) {
/**
* Nested DTO ActiveRuleParams
*/
- public List<ActiveRuleParamDto> selectParamsByActiveRuleId(DbSession dbSession, Integer activeRuleId) {
- return mapper(dbSession).selectParamsByActiveRuleId(activeRuleId);
+ public List<ActiveRuleParamDto> selectParamsByActiveRuleUuid(DbSession dbSession, String activeRuleUuid) {
+ return mapper(dbSession).selectParamsByActiveRuleUuid(activeRuleUuid);
}
- public List<ActiveRuleParamDto> selectParamsByActiveRuleIds(final DbSession dbSession, List<Integer> activeRuleIds) {
- return executeLargeInputs(activeRuleIds, mapper(dbSession)::selectParamsByActiveRuleIds);
+ public List<ActiveRuleParamDto> selectParamsByActiveRuleUuids(final DbSession dbSession, List<String> activeRuleUuids) {
+ return executeLargeInputs(activeRuleUuids, mapper(dbSession)::selectParamsByActiveRuleUuids);
}
public ActiveRuleParamDto insertParam(DbSession dbSession, ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam) {
- checkArgument(activeRule.getId() != null, ACTIVE_RULE_IS_NOT_PERSISTED);
+ 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);
- activeRuleParam.setActiveRuleId(activeRule.getId());
+ activeRuleParam.setActiveRuleUuid(activeRule.getUuid());
activeRuleParam.setUuid(uuidFactory.create());
mapper(dbSession).insertParameter(activeRuleParam);
return activeRuleParam;
public void deleteParam(DbSession dbSession, ActiveRuleParamDto activeRuleParam) {
Preconditions.checkNotNull(activeRuleParam.getUuid(), ACTIVE_RULE_PARAM_IS_NOT_PERSISTED);
- deleteParamById(dbSession, activeRuleParam.getUuid());
+ deleteParamByUuid(dbSession, activeRuleParam.getUuid());
}
- public void deleteParamById(DbSession dbSession, String uuid) {
+ public void deleteParamByUuid(DbSession dbSession, String uuid) {
mapper(dbSession).deleteParameter(uuid);
}
public void deleteParamsByRuleParamOfAllOrganizations(DbSession dbSession, RuleParamDto param) {
List<ActiveRuleDto> activeRules = selectByRuleIdOfAllOrganizations(dbSession, param.getRuleId());
for (ActiveRuleDto activeRule : activeRules) {
- for (ActiveRuleParamDto activeParam : selectParamsByActiveRuleId(dbSession, activeRule.getId())) {
+ for (ActiveRuleParamDto activeParam : selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid())) {
if (activeParam.getKey().equals(param.getName())) {
deleteParam(dbSession, activeParam);
}
}
}
- public void deleteParamsByActiveRuleIds(DbSession dbSession, List<Integer> activeRuleIds) {
+ public void deleteParamsByActiveRuleUuids(DbSession dbSession, List<String> activeRuleUuids) {
ActiveRuleMapper mapper = mapper(dbSession);
- DatabaseUtils.executeLargeUpdates(activeRuleIds, mapper::deleteParamsByActiveRuleIds);
+ DatabaseUtils.executeLargeUpdates(activeRuleUuids, mapper::deleteParamsByActiveRuleUuids);
}
public Map<String, Long> countActiveRulesByQuery(DbSession dbSession, ActiveRuleCountQuery query) {
});
}
- public void scrollByIdsForIndexing(DbSession dbSession, Collection<Long> ids, Consumer<IndexedActiveRuleDto> consumer) {
+ public void scrollByUuidsForIndexing(DbSession dbSession, Collection<String> uuids, Consumer<IndexedActiveRuleDto> consumer) {
ActiveRuleMapper mapper = mapper(dbSession);
- executeLargeInputsWithoutOutput(ids,
+ executeLargeInputsWithoutOutput(uuids,
pageOfIds -> mapper
- .scrollByIdsForIndexing(pageOfIds, context -> {
+ .scrollByUuidsForIndexing(pageOfIds, context -> {
IndexedActiveRuleDto dto = context.getResultObject();
consumer.accept(dto);
}));
public static final String INHERITED = ActiveRule.INHERITED;
public static final String OVERRIDES = ActiveRule.OVERRIDES;
- private Integer id;
+ private String uuid;
private Integer profileId;
private Integer ruleId;
private Integer severity;
return RuleKey.of(repository, ruleField);
}
- public Integer getId() {
- return id;
+ public String getUuid() {
+ return uuid;
}
- public ActiveRuleDto setId(Integer id) {
- this.id = id;
+ public ActiveRuleDto setUuid(String uuid) {
+ this.uuid = uuid;
return this;
}
void update(ActiveRuleDto dto);
- void delete(int activeRuleId);
+ void delete(String activeRuleUuid);
void deleteByRuleProfileUuids(@Param("rulesProfileUuids") Collection<String> rulesProfileUuids);
- void deleteByIds(@Param("ids") Collection<Integer> ids);
+ void deleteByUuids(@Param("uuids") Collection<String> uuids);
@CheckForNull
ActiveRuleDto selectByKey(@Param("ruleProfileUuid") String ruleProfileUuid, @Param("repository") String repository, @Param("rule") String rule);
void updateParameter(ActiveRuleParamDto dto);
- void deleteParameters(int activeRuleId);
+ void deleteParameters(String activeRuleUuid);
void deleteParametersByRuleProfileUuids(@Param("rulesProfileUuids") Collection<String> rulesProfileUuids);
void deleteParameter(String activeRuleParamUuid);
- void deleteParamsByActiveRuleIds(@Param("activeRuleIds") Collection<Integer> activeRuleIds);
+ void deleteParamsByActiveRuleUuids(@Param("activeRuleUuids") Collection<String> activeRuleUuids);
- List<ActiveRuleParamDto> selectParamsByActiveRuleId(int activeRuleId);
+ List<ActiveRuleParamDto> selectParamsByActiveRuleUuid(String activeRuleUuid);
- List<ActiveRuleParamDto> selectParamsByActiveRuleIds(@Param("ids") List<Integer> ids);
+ List<ActiveRuleParamDto> selectParamsByActiveRuleUuids(@Param("uuids") List<String> uuids);
List<KeyLongValue> countActiveRulesByQuery(@Param("organizationUuid") String organizationUuid, @Param("profileUuids") List<String> profileUuids,
@Nullable @Param("ruleStatus") RuleStatus ruleStatus, @Param("inheritance") String inheritance);
void scrollAllForIndexing(ResultHandler<IndexedActiveRuleDto> handler);
- void scrollByIdsForIndexing(@Param("ids") Collection<Long> ids, ResultHandler<IndexedActiveRuleDto> handler);
+ void scrollByUuidsForIndexing(@Param("uuids") Collection<String> uuids, ResultHandler<IndexedActiveRuleDto> handler);
void scrollByRuleProfileUuidForIndexing(@Param("ruleProfileUuid") String ruleProfileUuid, ResultHandler<IndexedActiveRuleDto> handler);
}
public class ActiveRuleParamDto {
private String uuid;
- private Integer activeRuleId;
+ private String activeRuleUuid;
private Integer rulesParameterId;
private String kee;
private String value;
return this;
}
- public Integer getActiveRuleId() {
- return activeRuleId;
+ public String getActiveRuleUuid() {
+ return activeRuleUuid;
}
- public ActiveRuleParamDto setActiveRuleId(Integer activeRuleId) {
- this.activeRuleId = activeRuleId;
+ public ActiveRuleParamDto setActiveRuleUuid(String activeRuleUuid) {
+ this.activeRuleUuid = activeRuleUuid;
return this;
}
import org.sonar.db.rule.SeverityUtil;
public class ExportRuleDto {
- private Integer activeRuleId = null;
+ private String activeRuleUuid = null;
private String repository = null;
private String rule = null;
private String name = null;
return template != null;
}
- public Integer getActiveRuleId() {
- return activeRuleId;
+ public String getActiveRuleUuid() {
+ return activeRuleUuid;
}
public RuleKey getRuleKey() {
package org.sonar.db.qualityprofile;
public class ExportRuleParamDto {
- private Integer activeRuleId = null;
+ private String activeRuleUuid = null;
private String kee = null;
private String value = null;
- public Integer getActiveRuleId() {
- return activeRuleId;
+ public String getActiveRuleUuid() {
+ return activeRuleUuid;
}
public String getKey() {
import javax.annotation.CheckForNull;
public class IndexedActiveRuleDto {
- private long id;
+ private String uuid;
private int ruleId;
private int severity;
private String inheritance;
private String key;
private String ruleProfileUuid;
- public long getId() {
- return id;
+ public String getUuid() {
+ return uuid;
}
public int getRuleId() {
public List<ExportRuleDto> selectRulesByProfile(DbSession dbSession, QProfileDto profile) {
List<ExportRuleDto> exportRules = mapper(dbSession).selectByProfileUuid(profile.getKee());
- Map<Integer, ExportRuleDto> exportRulesById = exportRules.stream().collect(Collectors.toMap(ExportRuleDto::getActiveRuleId, x -> x));
- Map<Integer, List<ExportRuleParamDto>> rulesParams = selectParamsByActiveRuleIds(dbSession, exportRulesById.keySet());
+ Map<String, ExportRuleDto> exportRulesByUuid = exportRules.stream().collect(Collectors.toMap(ExportRuleDto::getActiveRuleUuid, x -> x));
+ Map<String, List<ExportRuleParamDto>> rulesParams = selectParamsByActiveRuleUuids(dbSession, exportRulesByUuid.keySet());
- rulesParams.forEach((id, rules) -> exportRulesById.get(id).setParams(rules));
+ rulesParams.forEach((uuid, rules) -> exportRulesByUuid.get(uuid).setParams(rules));
return exportRules;
}
- private static Map<Integer, List<ExportRuleParamDto>> selectParamsByActiveRuleIds(DbSession dbSession, Collection<Integer> activeRuleIds) {
- return executeLargeInputs(activeRuleIds, ids -> mapper(dbSession).selectParamsByActiveRuleIds(ids))
+ private static Map<String, List<ExportRuleParamDto>> selectParamsByActiveRuleUuids(DbSession dbSession, Collection<String> activeRuleUuids) {
+ return executeLargeInputs(activeRuleUuids, uuids -> mapper(dbSession).selectParamsByActiveRuleUuids(uuids))
.stream()
- .collect(Collectors.groupingBy(ExportRuleParamDto::getActiveRuleId));
+ .collect(Collectors.groupingBy(ExportRuleParamDto::getActiveRuleUuid));
}
private static QualityProfileExportMapper mapper(DbSession dbSession) {
public interface QualityProfileExportMapper {
List<ExportRuleDto> selectByProfileUuid(String uuid);
- List<ExportRuleParamDto> selectParamsByActiveRuleIds(@Param("activeRuleIds") Collection<Integer> activeRuleIds);
+ List<ExportRuleParamDto> selectParamsByActiveRuleUuids(@Param("activeRuleUuids") Collection<String> activeRuleUuids);
}
<mapper namespace="org.sonar.db.qualityprofile.ActiveRuleMapper">
<sql id="activeRuleColumns">
- a.id,
+ a.uuid,
a.profile_id as "profileId",
a.rule_id as "ruleId",
a.failure_level as "severity",
</sql>
<sql id="orgActiveRuleColumns">
- a.id,
+ a.uuid,
a.profile_id as "profileId",
a.rule_id as "ruleId",
a.failure_level as "severity",
inner join rules r on r.id = a.rule_id
</sql>
- <insert id="insert" parameterType="ActiveRule" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ <insert id="insert" parameterType="ActiveRule">
insert into active_rules (
+ uuid,
profile_id,
rule_id,
failure_level,
created_at,
updated_at
) values (
+ #{uuid, jdbcType=VARCHAR},
#{profileId, jdbcType=BIGINT},
#{ruleId, jdbcType=BIGINT},
#{severity, jdbcType=INTEGER},
inheritance = #{inheritance, jdbcType=VARCHAR},
updated_at = #{updatedAt, jdbcType=BIGINT}
where
- id = #{id, jdbcType=BIGINT}
+ uuid = #{uuid, jdbcType=BIGINT}
</update>
- <delete id="delete" parameterType="int">
+ <delete id="delete" parameterType="String">
delete from active_rules
where
- id=#{id, jdbcType=BIGINT}
+ uuid=#{uuid, jdbcType=BIGINT}
</delete>
<delete id="deleteByRuleProfileUuids" parameterType="String">
)
</delete>
- <delete id="deleteByIds" parameterType="Integer">
+ <delete id="deleteByUuids" parameterType="String">
delete from active_rules
where
- id in
- <foreach collection="ids" open="(" close=")" item="id" separator=",">#{id, jdbcType=INTEGER}</foreach>
+ uuid in
+ <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
</delete>
<select id="selectByKey" parameterType="map" resultType="ActiveRule">
<sql id="activeRuleParamColumns">
p.uuid,
- p.active_rule_id as activeRuleId,
+ p.active_rule_uuid as activeRuleUuid,
p.rules_parameter_id as rulesParameterId,
p.rules_parameter_key as kee,
p.value as value
<insert id="insertParameter" parameterType="ActiveRuleParam" useGeneratedKeys="false">
insert into active_rule_parameters (
uuid,
- active_rule_id,
+ active_rule_uuid,
rules_parameter_id,
rules_parameter_key,
value
) values (
#{uuid, jdbcType=VARCHAR},
- #{activeRuleId, jdbcType=BIGINT},
+ #{activeRuleUuid, jdbcType=VARCHAR},
#{rulesParameterId, jdbcType=BIGINT},
#{key, jdbcType=VARCHAR},
#{value, jdbcType=VARCHAR}
WHERE uuid=#{uuid, jdbcType=VARCHAR}
</update>
- <delete id="deleteParameters" parameterType="int">
- DELETE FROM active_rule_parameters WHERE active_rule_id=#{activeRuleId, jdbcType=BIGINT}
+ <delete id="deleteParameters" parameterType="String">
+ DELETE FROM active_rule_parameters WHERE active_rule_uuid=#{activeRuleUuid, jdbcType=BIGINT}
</delete>
<delete id="deleteParametersByRuleProfileUuids" parameterType="String">
where exists (
select 1 from active_rules ar
inner join rules_profiles rp on rp.id = ar.profile_id
- where ar.id = active_rule_id
+ where ar.uuid = active_rule_uuid
and rp.kee in
<foreach collection="rulesProfileUuids" open="(" close=")" item="rulesProfileUuid" separator=",">
#{rulesProfileUuid, jdbcType=VARCHAR}
DELETE FROM active_rule_parameters WHERE uuid=#{uuid, jdbcType=VARCHAR}
</delete>
- <delete id="deleteParamsByActiveRuleIds" parameterType="Integer">
+ <delete id="deleteParamsByActiveRuleUuids" parameterType="String">
delete from active_rule_parameters
where
- active_rule_id in
- <foreach collection="activeRuleIds" open="(" close=")" item="activeRuleId" separator=",">#{activeRuleId, jdbcType=INTEGER}</foreach>
+ active_rule_uuid in
+ <foreach collection="activeRuleUuids" open="(" close=")" item="activeRuleUuid" separator=",">#{activeRuleUuid, jdbcType=VARCHAR}</foreach>
</delete>
- <select id="selectParamsByActiveRuleId" parameterType="Integer" resultType="ActiveRuleParam">
+ <select id="selectParamsByActiveRuleUuid" parameterType="String" resultType="ActiveRuleParam">
select
<include refid="activeRuleParamColumns"/>
from active_rule_parameters p
<where>
- p.active_rule_id=#{id, jdbcType=BIGINT}
+ p.active_rule_uuid=#{uuid, jdbcType=VARCHAR}
</where>
</select>
- <select id="selectParamsByActiveRuleIds" parameterType="map" resultType="ActiveRuleParam">
+ <select id="selectParamsByActiveRuleUuids" parameterType="map" resultType="ActiveRuleParam">
select
<include refid="activeRuleParamColumns"/>
from active_rule_parameters p
<where>
- <foreach collection="ids" item="id" open="(" separator=" or " close=")">
- p.active_rule_id=#{id, jdbcType=BIGINT}
+ <foreach collection="uuids" item="uuid" open="(" separator=" or " close=")">
+ p.active_rule_uuid=#{uuid, jdbcType=VARCHAR}
</foreach>
</where>
</select>
<select id="countActiveRulesByQuery" resultType="KeyLongValue" parameterType="map">
- select oqp.uuid as "key", count(ar.id) as "value"
+ select oqp.uuid as "key", count(ar.uuid) as "value"
from active_rules ar
inner join rules_profiles rp on rp.id = ar.profile_id
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
<include refid="scrollAllForIndexingSql"/>
</select>
- <select id="scrollByIdsForIndexing" parameterType="map" resultType="org.sonar.db.qualityprofile.IndexedActiveRuleDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
+ <select id="scrollByUuidsForIndexing" parameterType="map" resultType="org.sonar.db.qualityprofile.IndexedActiveRuleDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
<include refid="scrollAllForIndexingSql"/>
- where ar.id in
- <foreach collection="ids" open="(" close=")" item="id" separator=",">#{id, jdbcType=BIGINT}</foreach>
+ where ar.uuid in
+ <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
</select>
<select id="scrollByRuleProfileUuidForIndexing" parameterType="String" resultType="org.sonar.db.qualityprofile.IndexedActiveRuleDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
<sql id="scrollAllForIndexingSql">
select
- ar.id as "id",
+ ar.uuid as "uuid",
ar.failure_level as "severity",
ar.inheritance as "inheritance",
r.id as "ruleId",
<mapper namespace="org.sonar.db.qualityprofile.QualityProfileExportMapper">
<sql id="exportRuleColumns">
- a.id as "activeRuleId",
+ a.uuid as "activeRuleUuid",
a.failure_level as "severity",
r.plugin_rule_key as "rule",
r.plugin_name as "repository",
</sql>
<sql id="exportRuleParamColumns">
- p.active_rule_id as activeRuleId,
+ p.active_rule_uuid as activeRuleUuid,
p.rules_parameter_key as kee,
p.value as value
</sql>
where oqp.uuid = #{id, jdbcType=VARCHAR}
</select>
- <select id="selectParamsByActiveRuleIds" parameterType="map" resultType="org.sonar.db.qualityprofile.ExportRuleParamDto">
+ <select id="selectParamsByActiveRuleUuids" parameterType="map" resultType="org.sonar.db.qualityprofile.ExportRuleParamDto">
select
<include refid="exportRuleParamColumns"/>
from active_rule_parameters p
<where>
- p.active_rule_id in <foreach collection="activeRuleIds" open="(" close=")" item="activeRuleId" separator=",">#{activeRuleId,jdbcType=INTEGER}</foreach>
+ p.active_rule_uuid in <foreach collection="activeRuleUuids" open="(" close=")" item="activeRuleUuid" separator=",">#{activeRuleUuid,jdbcType=VARCHAR}</foreach>
</where>
</select>
</mapper>
);
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
+ "UUID" VARCHAR(40) NOT NULL,
+ "ACTIVE_RULE_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");
+CREATE INDEX "ARP_ACTIVE_RULE_UUID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_UUID");
CREATE TABLE "ACTIVE_RULES"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"PROFILE_ID" INTEGER NOT NULL,
"RULE_ID" INTEGER NOT NULL,
"FAILURE_LEVEL" INTEGER NOT NULL,
"INHERITANCE" VARCHAR(10),
"CREATED_AT" BIGINT,
- "UPDATED_AT" BIGINT
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL
);
-ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("ID");
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_ID", "RULE_ID");
CREATE TABLE "ALM_APP_INSTALLS"(
// match
result = underTest.selectByRulesAndRuleProfileUuids(dbSession, asList(rule1.getId()), asList(profile1.getRulesProfileUuid(), profile2.getRulesProfileUuid()));
assertThat(result)
- .extracting(ActiveRuleDto::getId)
- .containsExactlyInAnyOrder(rule1P1.getId(), rule1P2.getId());
+ .extracting(ActiveRuleDto::getUuid)
+ .containsExactlyInAnyOrder(rule1P1.getUuid(), rule1P2.getUuid());
result = underTest.selectByRulesAndRuleProfileUuids(dbSession, asList(rule1.getId(), rule2.getId()), asList(profile1.getRulesProfileUuid(), profile2.getRulesProfileUuid()));
assertThat(result)
- .extracting(ActiveRuleDto::getId)
- .containsExactlyInAnyOrder(rule1P1.getId(), rule1P2.getId(), rule2P1.getId());
+ .extracting(ActiveRuleDto::getUuid)
+ .containsExactlyInAnyOrder(rule1P1.getUuid(), rule1P2.getUuid(), rule2P1.getUuid());
// do not match
result = underTest.selectByRulesAndRuleProfileUuids(dbSession, asList(rule3.getId()), asList(profile1.getRulesProfileUuid(), profile2.getRulesProfileUuid()));
dbSession.commit();
ActiveRuleDto result = underTest.selectByKey(dbSession, activeRule.getKey()).get();
- assertThat(result.getId()).isEqualTo(activeRule.getId());
+ assertThat(result.getUuid()).isEqualTo(activeRule.getUuid());
assertThat(result.getKey()).isEqualTo(ActiveRuleKey.of(profile1, rule1.getKey()));
assertThat(result.getRuleId()).isEqualTo(rule1.getId());
assertThat(result.getProfileId()).isEqualTo(profile1.getId());
}
@Test
- public void fail_to_insert_when_rule_id_is_null() {
+ public void fail_to_insert_when_rule_uuid_is_null() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Rule is not persisted");
}
@Test
- public void fail_to_insert_when_id_is_not_null() {
+ public void fail_to_insert_when_uuid_is_not_null() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("ActiveRule is already persisted");
- underTest.insert(dbSession, createFor(profile1, rule1).setId(100));
+ underTest.insert(dbSession, createFor(profile1, rule1).setUuid("uuid"));
}
@Test
dbSession.commit();
ActiveRuleDto result = underTest.selectByKey(dbSession, ActiveRuleKey.of(profile1, rule1.getKey())).get();
- assertThat(result.getId()).isEqualTo(activeRule.getId());
+ assertThat(result.getUuid()).isEqualTo(activeRule.getUuid());
assertThat(result.getKey()).isEqualTo(ActiveRuleKey.of(profile1, rule1.getKey()));
assertThat(result.getRuleId()).isEqualTo(rule1.getId());
assertThat(result.getProfileId()).isEqualTo(profile1.getId());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Quality profile is not persisted (missing id)");
- underTest.update(dbSession, createFor(profile1, rule1).setId(100).setProfileId(null));
+ underTest.update(dbSession, createFor(profile1, rule1).setUuid("uuid").setProfileId(null));
}
@Test
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Rule is not persisted");
- underTest.update(dbSession, createFor(profile1, rule1).setId(100).setRuleId(null));
+ underTest.update(dbSession, createFor(profile1, rule1).setUuid("uuid").setRuleId(null));
}
@Test
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("ActiveRule is not persisted");
- underTest.update(dbSession, createFor(profile1, rule1).setId(null));
+ underTest.update(dbSession, createFor(profile1, rule1).setUuid(null));
}
@Test
ActiveRuleDto ar2 = underTest.insert(dbSession, newRow(profile1, rule2));
ActiveRuleDto ar3 = underTest.insert(dbSession, newRow(profile2, rule1));
- underTest.deleteByIds(dbSession, asList(ar1.getId(), ar3.getId()));
+ underTest.deleteByUuids(dbSession, asList(ar1.getUuid(), ar3.getUuid()));
assertThat(db.countRowsOfTable(dbSession, "active_rules")).isEqualTo(1);
assertThat(underTest.selectByProfile(dbSession, profile1))
- .extracting(ActiveRuleDto::getId)
- .containsExactly(ar2.getId());
+ .extracting(ActiveRuleDto::getUuid)
+ .containsExactly(ar2.getUuid());
}
@Test
public void deleteByIds_does_nothing_if_empty_list_of_ids() {
underTest.insert(dbSession, newRow(profile1, rule1));
- underTest.deleteByIds(dbSession, emptyList());
+ underTest.deleteByUuids(dbSession, emptyList());
assertThat(db.countRowsOfTable(dbSession, "active_rules")).isEqualTo(1);
}
underTest.insertParam(dbSession, activeRule, activeRuleParam2);
dbSession.commit();
- assertThat(underTest.selectParamsByActiveRuleId(dbSession, activeRule.getId())).hasSize(2);
+ assertThat(underTest.selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid())).hasSize(2);
}
@Test
underTest.insertParam(dbSession, activeRule2, ActiveRuleParamDto.createFor(rule2Param1));
dbSession.commit();
- assertThat(underTest.selectParamsByActiveRuleIds(dbSession, asList(activeRule1.getId(), activeRule2.getId()))).hasSize(3);
+ assertThat(underTest.selectParamsByActiveRuleUuids(dbSession, asList(activeRule1.getUuid(), activeRule2.getUuid()))).hasSize(3);
}
@Test
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(rule1Param1).setValue("foo");
underTest.insertParam(dbSession, activeRule, activeRuleParam);
- List<ActiveRuleParamDto> reloaded = underTest.selectParamsByActiveRuleId(dbSession, activeRule.getId());
+ List<ActiveRuleParamDto> reloaded = underTest.selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid());
assertThat(reloaded).hasSize(1);
assertThat(reloaded.get(0))
.matches(p -> Objects.equals(p.getUuid(), activeRuleParam.getUuid()))
.matches(p -> p.getKey().equals(activeRuleParam.getKey()))
- .matches(p -> p.getActiveRuleId().equals(activeRule.getId()))
+ .matches(p -> p.getActiveRuleUuid().equals(activeRule.getUuid()))
.matches(p -> p.getRulesParameterId().equals(rule1Param1.getId()))
.matches(p -> p.getValue().equals("foo"));
}
thrown.expectMessage("ActiveRule is not persisted");
underTest.insertParam(dbSession,
- createFor(profile1, rule1).setId(null),
+ createFor(profile1, rule1).setUuid(null),
ActiveRuleParamDto.createFor(rule1Param1).setValue("activeValue1"));
}
thrown.expectMessage("ActiveRuleParam is already persisted");
underTest.insertParam(dbSession,
- createFor(profile1, rule1).setId(100),
+ createFor(profile1, rule1).setUuid("uuid"),
ActiveRuleParamDto.createFor(rule1Param1).setValue("activeValue1").setUuid("uuid-1"));
}
@Test
- public void insertParam_fails_when_id_is_not_null() {
+ public void insertParam_fails_when_uuid_is_not_null() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("Rule param is not persisted");
underTest.insertParam(dbSession,
- createFor(profile1, rule1).setId(100),
+ createFor(profile1, rule1).setUuid("uuid"),
ActiveRuleParamDto.createFor(rule1Param1).setValue("activeValue1").setRulesParameterId(null));
}
underTest.updateParam(dbSession, activeRuleParam.setValue("bar"));
- List<ActiveRuleParamDto> reloaded = underTest.selectParamsByActiveRuleId(dbSession, activeRule.getId());
+ List<ActiveRuleParamDto> reloaded = underTest.selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid());
assertThat(reloaded).hasSize(1);
assertThat(reloaded.get(0))
.matches(p -> Objects.equals(p.getUuid(), activeRuleParam.getUuid()))
.matches(p -> p.getKey().equals(activeRuleParam.getKey()))
- .matches(p -> p.getActiveRuleId().equals(activeRule.getId()))
+ .matches(p -> p.getActiveRuleUuid().equals(activeRule.getUuid()))
.matches(p -> p.getRulesParameterId().equals(rule1Param1.getId()))
.matches(p -> p.getValue().equals("bar"));
}
underTest.deleteParam(dbSession, param);
- assertThat(underTest.selectParamsByActiveRuleId(dbSession, activeRule.getId())).hasSize(0);
+ assertThat(underTest.selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid())).hasSize(0);
}
@Test
underTest.deleteParametersByRuleProfileUuids(dbSession, asList(profile1.getRulesProfileUuid(), "does_not_exist"));
- assertThat(underTest.selectParamsByActiveRuleId(dbSession, activeRuleInProfile1.getId())).isEmpty();
- assertThat(underTest.selectParamsByActiveRuleId(dbSession, activeRuleInProfile2.getId()))
+ assertThat(underTest.selectParamsByActiveRuleUuid(dbSession, activeRuleInProfile1.getUuid())).isEmpty();
+ assertThat(underTest.selectParamsByActiveRuleUuid(dbSession, activeRuleInProfile2.getUuid()))
.extracting(ActiveRuleParamDto::getKey, ActiveRuleParamDto::getValue)
.containsExactly(tuple(rule1Param1.getName(), "bar"));
}
underTest.deleteParametersByRuleProfileUuids(dbSession, emptyList());
- assertThat(underTest.selectParamsByActiveRuleId(dbSession, activeRuleInProfile1.getId()))
+ assertThat(underTest.selectParamsByActiveRuleUuid(dbSession, activeRuleInProfile1.getUuid()))
.hasSize(1);
}
ActiveRuleParamDto activeRuleParam2 = ActiveRuleParamDto.createFor(rule1Param1).setValue("bar");
underTest.insertParam(dbSession, activeRule2, activeRuleParam2);
- List<Integer> activeRuleIds = asList(activeRule1.getId(), activeRule2.getId());
- assertThat(underTest.selectParamsByActiveRuleIds(dbSession, activeRuleIds)).hasSize(2);
+ List<String> activeRuleUuids = asList(activeRule1.getUuid(), activeRule2.getUuid());
+ assertThat(underTest.selectParamsByActiveRuleUuids(dbSession, activeRuleUuids)).hasSize(2);
underTest.deleteParamsByRuleParamOfAllOrganizations(dbSession, rule1Param1);
- assertThat(underTest.selectParamsByActiveRuleIds(dbSession, activeRuleIds)).isEmpty();
+ assertThat(underTest.selectParamsByActiveRuleUuids(dbSession, activeRuleUuids)).isEmpty();
}
@Test
ActiveRuleParamDto param2 = ActiveRuleParamDto.createFor(rule2Param1).setValue("bar");
underTest.insertParam(dbSession, ar2, param2);
- underTest.deleteParamsByActiveRuleIds(dbSession, asList(ar1.getId()));
+ underTest.deleteParamsByActiveRuleUuids(dbSession, asList(ar1.getUuid()));
- assertThat(underTest.selectParamsByActiveRuleId(dbSession, ar1.getId())).hasSize(0);
- assertThat(underTest.selectParamsByActiveRuleId(dbSession, ar2.getId())).hasSize(1);
+ assertThat(underTest.selectParamsByActiveRuleUuid(dbSession, ar1.getUuid())).hasSize(0);
+ assertThat(underTest.selectParamsByActiveRuleUuid(dbSession, ar2.getUuid())).hasSize(1);
}
@Test
Accumulator accumulator = new Accumulator();
underTest.scrollAllForIndexing(dbSession, accumulator);
assertThat(accumulator.list)
- .extracting(IndexedActiveRuleDto::getId,
+ .extracting(IndexedActiveRuleDto::getUuid,
IndexedActiveRuleDto::getRuleId, IndexedActiveRuleDto::getRepository, IndexedActiveRuleDto::getKey,
IndexedActiveRuleDto::getRuleProfileUuid,
IndexedActiveRuleDto::getSeverity, IndexedActiveRuleDto::getInheritance)
.containsExactlyInAnyOrder(
- tuple((long)ar1.getId(), rule1.getId(), ar1.getRuleKey().repository(), ar1.getRuleKey().rule(), profile1.getRulesProfileUuid(), ar1.getSeverity(), ar1.getInheritance()),
- tuple((long)ar2.getId(), rule1.getId(), ar2.getRuleKey().repository(), ar2.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar2.getSeverity(), ar2.getInheritance()),
- tuple((long)ar3.getId(), rule2.getId(), ar3.getRuleKey().repository(), ar3.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar3.getSeverity(), ar3.getInheritance()));
+ tuple(ar1.getUuid(), rule1.getId(), ar1.getRuleKey().repository(), ar1.getRuleKey().rule(), profile1.getRulesProfileUuid(), ar1.getSeverity(), ar1.getInheritance()),
+ tuple(ar2.getUuid(), rule1.getId(), ar2.getRuleKey().repository(), ar2.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar2.getSeverity(), ar2.getInheritance()),
+ tuple(ar3.getUuid(), rule2.getId(), ar3.getRuleKey().repository(), ar3.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar3.getSeverity(), ar3.getInheritance()));
}
@Test
ActiveRuleDto ar3 = db.qualityProfiles().activateRule(profile2, rule2);
Accumulator accumulator = new Accumulator();
- underTest.scrollByIdsForIndexing(dbSession, asList((long) ar1.getId(), (long) ar2.getId()), accumulator);
+ underTest.scrollByUuidsForIndexing(dbSession, asList( ar1.getUuid(), ar2.getUuid()), accumulator);
assertThat(accumulator.list)
- .extracting(IndexedActiveRuleDto::getId,
+ .extracting(IndexedActiveRuleDto::getUuid,
IndexedActiveRuleDto::getRuleId, IndexedActiveRuleDto::getRepository, IndexedActiveRuleDto::getKey,
IndexedActiveRuleDto::getRuleProfileUuid, IndexedActiveRuleDto::getSeverity)
.containsExactlyInAnyOrder(
- tuple((long)ar1.getId(), rule1.getId(), ar1.getRuleKey().repository(), ar1.getRuleKey().rule(), profile1.getRulesProfileUuid(), ar1.getSeverity()),
- tuple((long)ar2.getId(), rule1.getId(), ar2.getRuleKey().repository(), ar2.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar2.getSeverity()));
+ tuple(ar1.getUuid(), rule1.getId(), ar1.getRuleKey().repository(), ar1.getRuleKey().rule(), profile1.getRulesProfileUuid(), ar1.getSeverity()),
+ tuple(ar2.getUuid(), rule1.getId(), ar2.getRuleKey().repository(), ar2.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar2.getSeverity()));
}
@Test
Accumulator accumulator = new Accumulator();
underTest.scrollByRuleProfileForIndexing(dbSession, profile2.getRulesProfileUuid(), accumulator);
assertThat(accumulator.list)
- .extracting(IndexedActiveRuleDto::getId, IndexedActiveRuleDto::getRepository, IndexedActiveRuleDto::getKey, IndexedActiveRuleDto::getRuleProfileUuid,
+ .extracting(IndexedActiveRuleDto::getUuid, IndexedActiveRuleDto::getRepository, IndexedActiveRuleDto::getKey, IndexedActiveRuleDto::getRuleProfileUuid,
IndexedActiveRuleDto::getSeverity)
.containsExactlyInAnyOrder(
- tuple((long) ar2.getId(), ar2.getRuleKey().repository(), ar2.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar2.getSeverity()),
- tuple((long) ar3.getId(), ar3.getRuleKey().repository(), ar3.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar3.getSeverity()));
+ tuple(ar2.getUuid(), ar2.getRuleKey().repository(), ar2.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar2.getSeverity()),
+ tuple(ar3.getUuid(), ar3.getRuleKey().repository(), ar3.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar3.getSeverity()));
}
private static class Accumulator implements Consumer<IndexedActiveRuleDto> {
List<ExportRuleDto> results = underTest.selectRulesByProfile(dbSession, profile);
assertThat(results)
- .extracting("activeRuleId")
- .containsOnly(activatedRule.getId());
+ .extracting("activeRuleUuid")
+ .containsOnly(activatedRule.getUuid());
assertThat(results.get(0).getParams())
.extracting("key")
List<ExportRuleDto> otherProfileResults = underTest.selectRulesByProfile(dbSession, otherProfile);
assertThat(results)
- .extracting("activeRuleId")
- .containsOnly(firstActivatedRule.getId(), secondActivatedRule.getId());
+ .extracting("activeRuleUuid")
+ .containsOnly(firstActivatedRule.getUuid(), secondActivatedRule.getUuid());
assertThat(otherProfileResults)
- .extracting("activeRuleId")
- .containsOnly(thirdActivatedRule.getId());
+ .extracting("activeRuleUuid")
+ .containsOnly(thirdActivatedRule.getUuid());
- ExportRuleDto firstExportedRule = findExportedRuleById(firstActivatedRule.getId(), results);
+ ExportRuleDto firstExportedRule = findExportedRuleByUuid(firstActivatedRule.getUuid(), results);
assertThat(firstExportedRule.getParams())
.extracting("key")
.containsOnly(ruleParamsOfFirstRule.stream().map(RuleParamDto::getName).toArray());
- ExportRuleDto secondExportedRule = findExportedRuleById(secondActivatedRule.getId(), results);
+ ExportRuleDto secondExportedRule = findExportedRuleByUuid(secondActivatedRule.getUuid(), results);
assertThat(secondExportedRule.getParams())
.extracting("key")
.containsOnly(ruleParamsOfSecondRule.stream().map(RuleParamDto::getName).toArray());
- ExportRuleDto thirdExportedRule = findExportedRuleById(thirdActivatedRule.getId(), otherProfileResults);
+ ExportRuleDto thirdExportedRule = findExportedRuleByUuid(thirdActivatedRule.getUuid(), otherProfileResults);
assertThat(thirdExportedRule.getParams())
.extracting("key")
.containsOnly(ruleParamsOfThirdRule.stream().map(RuleParamDto::getName).toArray());
}
- private ExportRuleDto findExportedRuleById(Integer id, List<ExportRuleDto> results) {
- Optional<ExportRuleDto> found = results.stream().filter(exportRuleDto -> id.equals(exportRuleDto.getActiveRuleId())).findFirst();
+ private ExportRuleDto findExportedRuleByUuid(String uuid, List<ExportRuleDto> results) {
+ Optional<ExportRuleDto> found = results.stream().filter(exportRuleDto -> uuid.equals(exportRuleDto.getActiveRuleUuid())).findFirst();
if (!found.isPresent()) {
Assert.fail();
}
ActiveRuleParamDto dto = ActiveRuleParamDto.createFor(ruleParamDto)
.setKey(ruleParamDto.getName())
.setValue("20")
- .setActiveRuleId(activeRule.getId());
+ .setActiveRuleUuid(activeRule.getUuid());
db.getDbClient().activeRuleDao().insertParam(db.getSession(), activeRule, dto);
});
import org.sonar.server.platform.db.migration.version.v83.activeruleparameters.DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable;
import org.sonar.server.platform.db.migration.version.v83.activeruleparameters.MakeActiveRuleParametersUuidColumnNotNullable;
import org.sonar.server.platform.db.migration.version.v83.activeruleparameters.PopulateActiveRuleParametersUuid;
+import org.sonar.server.platform.db.migration.version.v83.activerules.AddActiveRuleUuidColumnToActiveRuleParameters;
+import org.sonar.server.platform.db.migration.version.v83.activerules.AddIndexOnActiveRuleUuidOfActiveRuleParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.activerules.AddPrimaryKeyOnUuidColumnOfActiveRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.activerules.AddUuidColumnToActiveRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.activerules.DropActiveRuleIdColumnOfActiveRuleParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.activerules.DropIdColumnOfActiveRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.activerules.DropIndexOnActiveRuleIdOfActiveRuleParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.activerules.DropPrimaryKeyOnIdColumnOfActiveRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.activerules.MakeActiveRuleParametersActiveRuleUuidNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.activerules.MakeActiveRulesUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.activerules.PopulateActiveRuleParametersActiveRuleUuid;
+import org.sonar.server.platform.db.migration.version.v83.activerules.PopulateActiveRulesUuid;
import org.sonar.server.platform.db.migration.version.v83.ceactivity.AddPrimaryKeyOnUuidColumnOfCeActivityTable;
import org.sonar.server.platform.db.migration.version.v83.ceactivity.DropIdColumnOfCeActivityTable;
import org.sonar.server.platform.db.migration.version.v83.ceactivity.DropPrimaryKeyOnIdColumnOfCeActivityTable;
.add(3456, "Add primary key on 'UUID' column of 'MANUAL_MEASURES' table", AddPrimaryKeyOnUuidColumnOfManualMeasuresTable.class)
.add(3457, "Drop column 'ID' of 'MANUAL_MEASURES' table", DropIdColumnOfManualMeasuresTable.class)
- // Migration on CE_ACTIVITY table
- .add(3458, "Drop primary key on 'ID' column of 'GROUP_ROLES' table", DropPrimaryKeyOnIdColumnOfGroupRolesTable.class)
- .add(3459, "Add primary key on 'UUID' column of 'GROUP_ROLES' table", AddPrimaryKeyOnUuidColumnOfGroupRolesTable.class)
- .add(3460, "Drop column 'ID' of 'GROUP_ROLES' table", DropIdColumnOfGroupRolesTable.class)
-
// Migration of GROUP_ROLES table
- .add(3461, "Add 'UUID' column on 'GROUP_ROLES' table", AddUuidColumnToGroupRolesTable.class)
- .add(3462, "Populate 'uuid' for 'GROUP_ROLES'", PopulateGroupRolesUuid.class)
- .add(3463, "Make 'uuid' column not nullable for 'GROUP_ROLES'", MakeGroupRolesUuidColumnNotNullable.class)
- .add(3464, "Drop primary key on 'ID' column of 'GROUP_ROLES' table", DropPrimaryKeyOnIdColumnOfGroupRolesTable.class)
- .add(3465, "Add primary key on 'UUID' column of 'GROUP_ROLES' table", AddPrimaryKeyOnUuidColumnOfGroupRolesTable.class)
- .add(3466, "Drop column 'ID' of 'GROUP_ROLES' table", DropIdColumnOfGroupRolesTable.class)
+ .add(3458, "Add 'UUID' column on 'GROUP_ROLES' table", AddUuidColumnToGroupRolesTable.class)
+ .add(3459, "Populate 'uuid' for 'GROUP_ROLES'", PopulateGroupRolesUuid.class)
+ .add(3460, "Make 'uuid' column not nullable for 'GROUP_ROLES'", MakeGroupRolesUuidColumnNotNullable.class)
+ .add(3461, "Drop primary key on 'ID' column of 'GROUP_ROLES' table", DropPrimaryKeyOnIdColumnOfGroupRolesTable.class)
+ .add(3462, "Add primary key on 'UUID' column of 'GROUP_ROLES' table", AddPrimaryKeyOnUuidColumnOfGroupRolesTable.class)
+ .add(3463, "Drop column 'ID' of 'GROUP_ROLES' table", DropIdColumnOfGroupRolesTable.class)
// Migration of USER_ROLES table
- .add(3467, "Add 'UUID' column on 'USER_ROLES' table", AddUuidColumnToUserRolesTable.class)
- .add(3468, "Populate 'uuid' for 'USER_ROLES'", PopulateUserRolesUuid.class)
- .add(3469, "Make 'uuid' column not nullable for 'USER_ROLES'", MakeUserRolesUuidColumnNotNullable.class)
- .add(3470, "Drop primary key on 'ID' column of 'USER_ROLES' table", DropPrimaryKeyOnIdColumnOfUserRolesTable.class)
- .add(3471, "Add primary key on 'UUID' column of 'USER_ROLES' table", AddPrimaryKeyOnUuidColumnOfUserRolesTable.class)
- .add(3472, "Drop column 'ID' of 'USER_ROLES' table", DropIdColumnOfUserRolesTable.class)
+ .add(3464, "Add 'UUID' column on 'USER_ROLES' table", AddUuidColumnToUserRolesTable.class)
+ .add(3465, "Populate 'uuid' for 'USER_ROLES'", PopulateUserRolesUuid.class)
+ .add(3466, "Make 'uuid' column not nullable for 'USER_ROLES'", MakeUserRolesUuidColumnNotNullable.class)
+ .add(3467, "Drop primary key on 'ID' column of 'USER_ROLES' table", DropPrimaryKeyOnIdColumnOfUserRolesTable.class)
+ .add(3468, "Add primary key on 'UUID' column of 'USER_ROLES' table", AddPrimaryKeyOnUuidColumnOfUserRolesTable.class)
+ .add(3469, "Drop column 'ID' of 'USER_ROLES' table", DropIdColumnOfUserRolesTable.class)
// Migration of FILE_SOURCES table
- .add(3473, "Add 'UUID' column on 'FILE_SOURCES' table", AddUuidColumnToFileSourcesTable.class)
- .add(3474, "Populate 'uuid' for 'FILE_SOURCES'", PopulateFileSourcesUuid.class)
- .add(3475, "Make 'uuid' column not nullable for 'FILE_SOURCES'", MakeFileSourcesUuidColumnNotNullable.class)
- .add(3476, "Drop primary key on 'ID' column of 'FILE_SOURCES' table", DropPrimaryKeyOnIdColumnOfFileSourcesTable.class)
- .add(3477, "Add primary key on 'UUID' column of 'FILE_SOURCES' table", AddPrimaryKeyOnUuidColumnOfFileSourcesTable.class)
- .add(3478, "Drop column 'ID' of 'FILE_SOURCES' table", DropIdColumnOfFileSourcesTable.class)
-
- // Migration of GROUP_ROLES table
- .add(3479, "Add 'UUID' column on 'GROUP_ROLES' table", AddUuidColumnToGroupRolesTable.class)
- .add(3480, "Populate 'uuid' for 'GROUP_ROLES'", PopulateGroupRolesUuid.class)
- .add(3481, "Make 'uuid' column not nullable for 'GROUP_ROLES'", MakeGroupRolesUuidColumnNotNullable.class)
- .add(3482, "Drop primary key on 'ID' column of 'GROUP_ROLES' table", DropPrimaryKeyOnIdColumnOfGroupRolesTable.class)
- .add(3483, "Add primary key on 'UUID' column of 'GROUP_ROLES' table", AddPrimaryKeyOnUuidColumnOfGroupRolesTable.class)
- .add(3484, "Drop column 'ID' of 'GROUP_ROLES' table", DropIdColumnOfGroupRolesTable.class)
-
- // Migration of USER_ROLES table
- .add(3485, "Add 'UUID' column on 'USER_ROLES' table", AddUuidColumnToUserRolesTable.class)
- .add(3486, "Populate 'uuid' for 'USER_ROLES'", PopulateUserRolesUuid.class)
- .add(3487, "Make 'uuid' column not nullable for 'USER_ROLES'", MakeUserRolesUuidColumnNotNullable.class)
- .add(3488, "Drop primary key on 'ID' column of 'USER_ROLES' table", DropPrimaryKeyOnIdColumnOfUserRolesTable.class)
- .add(3489, "Add primary key on 'UUID' column of 'USER_ROLES' table", AddPrimaryKeyOnUuidColumnOfUserRolesTable.class)
- .add(3490, "Drop column 'ID' of 'USER_ROLES' table", DropIdColumnOfUserRolesTable.class)
-
- // Migration of FILE_SOURCES table
- .add(3491, "Add 'UUID' column on 'FILE_SOURCES' table", AddUuidColumnToFileSourcesTable.class)
- .add(3492, "Populate 'uuid' for 'FILE_SOURCES'", PopulateFileSourcesUuid.class)
- .add(3493, "Make 'uuid' column not nullable for 'FILE_SOURCES'", MakeFileSourcesUuidColumnNotNullable.class)
- .add(3494, "Drop primary key on 'ID' column of 'FILE_SOURCES' table", DropPrimaryKeyOnIdColumnOfFileSourcesTable.class)
- .add(3495, "Add primary key on 'UUID' column of 'FILE_SOURCES' table", AddPrimaryKeyOnUuidColumnOfFileSourcesTable.class)
- .add(3496, "Drop column 'ID' of 'FILE_SOURCES' table", DropIdColumnOfFileSourcesTable.class)
+ .add(3470, "Add 'UUID' column on 'FILE_SOURCES' table", AddUuidColumnToFileSourcesTable.class)
+ .add(3471, "Populate 'uuid' for 'FILE_SOURCES'", PopulateFileSourcesUuid.class)
+ .add(3472, "Make 'uuid' column not nullable for 'FILE_SOURCES'", MakeFileSourcesUuidColumnNotNullable.class)
+ .add(3473, "Drop primary key on 'ID' column of 'FILE_SOURCES' table", DropPrimaryKeyOnIdColumnOfFileSourcesTable.class)
+ .add(3474, "Add primary key on 'UUID' column of 'FILE_SOURCES' table", AddPrimaryKeyOnUuidColumnOfFileSourcesTable.class)
+ .add(3475, "Drop column 'ID' of 'FILE_SOURCES' table", DropIdColumnOfFileSourcesTable.class)
// Migration of ISSUE_CHANGES table
- .add(3464, "Add 'UUID' column on 'ISSUE_CHANGES' table", AddUuidColumnToIssueChangesTable.class)
- .add(3465, "Populate 'uuid' for 'ISSUE_CHANGES'", PopulateIssueChangesUuid.class)
- .add(3466, "Make 'uuid' column not nullable for 'ISSUE_CHANGES'", MakeIssueChangesUuidColumnNotNullable.class)
- .add(3467, "Drop primary key on 'ID' column of 'ISSUE_CHANGES' table", DropPrimaryKeyOnIdColumnOfIssueChangesTable.class)
- .add(3468, "Add primary key on 'UUID' column of 'ISSUE_CHANGES' table", AddPrimaryKeyOnUuidColumnOfIssueChangesTable.class)
- .add(3469, "Drop column 'ID' of 'ISSUE_CHANGES' table", DropIdColumnOfIssueChangesTable.class)
+ .add(3476, "Add 'UUID' column on 'ISSUE_CHANGES' table", AddUuidColumnToIssueChangesTable.class)
+ .add(3477, "Populate 'uuid' for 'ISSUE_CHANGES'", PopulateIssueChangesUuid.class)
+ .add(3478, "Make 'uuid' column not nullable for 'ISSUE_CHANGES'", MakeIssueChangesUuidColumnNotNullable.class)
+ .add(3479, "Drop primary key on 'ID' column of 'ISSUE_CHANGES' table", DropPrimaryKeyOnIdColumnOfIssueChangesTable.class)
+ .add(3480, "Add primary key on 'UUID' column of 'ISSUE_CHANGES' table", AddPrimaryKeyOnUuidColumnOfIssueChangesTable.class)
+ .add(3481, "Drop column 'ID' of 'ISSUE_CHANGES' table", DropIdColumnOfIssueChangesTable.class)
// Migration of QUALITY_GATE_CONDITIONS table
- .add(3470, "Add 'UUID' column on 'QUALITY_GATE_CONDITIONS' table", AddUuidColumnToQualityGateConditionsTable.class)
- .add(3471, "Populate 'uuid' for 'QUALITY_GATE_CONDITIONS'", PopulateQualityGateConditionsUuid.class)
- .add(3472, "Make 'uuid' column not nullable for 'QUALITY_GATE_CONDITIONS'", MakeQualityGateConditionsUuidColumnNotNullable.class)
- .add(3473, "Drop primary key on 'ID' column of 'QUALITY_GATE_CONDITIONS' table", DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable.class)
- .add(3474, "Add primary key on 'UUID' column of 'QUALITY_GATE_CONDITIONS' table", AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable.class)
- .add(3475, "Drop column 'ID' of 'QUALITY_GATE_CONDITIONS' table", DropIdColumnOfQualityGateConditionsTable.class)
+ .add(3482, "Add 'UUID' column on 'QUALITY_GATE_CONDITIONS' table", AddUuidColumnToQualityGateConditionsTable.class)
+ .add(3483, "Populate 'uuid' for 'QUALITY_GATE_CONDITIONS'", PopulateQualityGateConditionsUuid.class)
+ .add(3484, "Make 'uuid' column not nullable for 'QUALITY_GATE_CONDITIONS'", MakeQualityGateConditionsUuidColumnNotNullable.class)
+ .add(3485, "Drop primary key on 'ID' column of 'QUALITY_GATE_CONDITIONS' table", DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable.class)
+ .add(3486, "Add primary key on 'UUID' column of 'QUALITY_GATE_CONDITIONS' table", AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable.class)
+ .add(3487, "Drop column 'ID' of 'QUALITY_GATE_CONDITIONS' table", DropIdColumnOfQualityGateConditionsTable.class)
// Migration of PERM_TEMPLATES_GROUPS table
- .add(3476, "Add 'UUID' column on 'PERM_TEMPLATES_GROUPS' table", AddUuidColumnToPermTemplatesGroupsTable.class)
- .add(3477, "Populate 'uuid' for 'PERM_TEMPLATES_GROUPS'", PopulatePermTemplatesGroupsUuid.class)
- .add(3478, "Make 'uuid' column not nullable for 'PERM_TEMPLATES_GROUPS'", MakePermTemplatesGroupsUuidColumnNotNullable.class)
- .add(3479, "Drop primary key on 'ID' column of 'PERM_TEMPLATES_GROUPS' table", DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable.class)
- .add(3480, "Add primary key on 'UUID' column of 'PERM_TEMPLATES_GROUPS' table", AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTable.class)
- .add(3481, "Drop column 'ID' of 'PERM_TEMPLATES_GROUPS' table", DropIdColumnOfPermTemplatesGroupsTable.class)
+ .add(3488, "Add 'UUID' column on 'PERM_TEMPLATES_GROUPS' table", AddUuidColumnToPermTemplatesGroupsTable.class)
+ .add(3489, "Populate 'uuid' for 'PERM_TEMPLATES_GROUPS'", PopulatePermTemplatesGroupsUuid.class)
+ .add(3490, "Make 'uuid' column not nullable for 'PERM_TEMPLATES_GROUPS'", MakePermTemplatesGroupsUuidColumnNotNullable.class)
+ .add(3491, "Drop primary key on 'ID' column of 'PERM_TEMPLATES_GROUPS' table", DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable.class)
+ .add(3492, "Add primary key on 'UUID' column of 'PERM_TEMPLATES_GROUPS' table", AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTable.class)
+ .add(3493, "Drop column 'ID' of 'PERM_TEMPLATES_GROUPS' table", DropIdColumnOfPermTemplatesGroupsTable.class)
// Migration of PERM_TPL_CHARACTERISTICS table
- .add(3482, "Add 'UUID' column on 'PERM_TPL_CHARACTERISTICS' table", AddUuidColumnToPermTplCharacteristicsTable.class)
- .add(3483, "Populate 'uuid' for 'PERM_TPL_CHARACTERISTICS'", PopulatePermTplCharacteristicsUuid.class)
- .add(3484, "Make 'uuid' column not nullable for 'PERM_TPL_CHARACTERISTICS'", MakePermTplCharacteristicsUuidColumnNotNullable.class)
- .add(3485, "Drop primary key on 'ID' column of 'PERM_TPL_CHARACTERISTICS' table", DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable.class)
- .add(3486, "Add primary key on 'UUID' column of 'PERM_TPL_CHARACTERISTICS' table", AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTable.class)
- .add(3487, "Drop column 'ID' of 'PERM_TPL_CHARACTERISTICS' table", DropIdColumnOfPermTplCharacteristicsTable.class)
+ .add(3494, "Add 'UUID' column on 'PERM_TPL_CHARACTERISTICS' table", AddUuidColumnToPermTplCharacteristicsTable.class)
+ .add(3495, "Populate 'uuid' for 'PERM_TPL_CHARACTERISTICS'", PopulatePermTplCharacteristicsUuid.class)
+ .add(3496, "Make 'uuid' column not nullable for 'PERM_TPL_CHARACTERISTICS'", MakePermTplCharacteristicsUuidColumnNotNullable.class)
+ .add(3497, "Drop primary key on 'ID' column of 'PERM_TPL_CHARACTERISTICS' table", DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable.class)
+ .add(3498, "Add primary key on 'UUID' column of 'PERM_TPL_CHARACTERISTICS' table", AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTable.class)
+ .add(3499, "Drop column 'ID' of 'PERM_TPL_CHARACTERISTICS' table", DropIdColumnOfPermTplCharacteristicsTable.class)
// Migration of PERM_TEMPLATES_USERS table
- .add(3488, "Add 'UUID' column on 'PERM_TEMPLATES_USERS' table", AddUuidColumnToPermTemplatesUsersTable.class)
- .add(3489, "Populate 'uuid' for 'PERM_TEMPLATES_USERS'", PopulatePermTemplatesUsersUuid.class)
- .add(3490, "Make 'uuid' column not nullable for 'PERM_TEMPLATES_USERS'", MakePermTemplatesUsersUuidColumnNotNullable.class)
- .add(3491, "Drop primary key on 'ID' column of 'PERM_TEMPLATES_USERS' table", DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable.class)
- .add(3492, "Add primary key on 'UUID' column of 'PERM_TEMPLATES_USERS' table", AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable.class)
- .add(3493, "Drop column 'ID' of 'PERM_TEMPLATES_USERS' table", DropIdColumnOfPermTemplatesUsersTable.class)
+ .add(3500, "Add 'UUID' column on 'PERM_TEMPLATES_USERS' table", AddUuidColumnToPermTemplatesUsersTable.class)
+ .add(3501, "Populate 'uuid' for 'PERM_TEMPLATES_USERS'", PopulatePermTemplatesUsersUuid.class)
+ .add(3502, "Make 'uuid' column not nullable for 'PERM_TEMPLATES_USERS'", MakePermTemplatesUsersUuidColumnNotNullable.class)
+ .add(3503, "Drop primary key on 'ID' column of 'PERM_TEMPLATES_USERS' table", DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable.class)
+ .add(3504, "Add primary key on 'UUID' column of 'PERM_TEMPLATES_USERS' table", AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable.class)
+ .add(3505, "Drop column 'ID' of 'PERM_TEMPLATES_USERS' table", DropIdColumnOfPermTemplatesUsersTable.class)
+
+ // Migration of ACTIVE_RULES table
+ .add(3506, "Add 'UUID' column on 'ACTIVE_RULES' table", AddUuidColumnToActiveRulesTable.class)
+ .add(3507, "Populate 'uuid' for 'ACTIVE_RULES'", PopulateActiveRulesUuid.class)
+ .add(3508, "Make 'uuid' column not nullable for 'ACTIVE_RULES'", MakeActiveRulesUuidColumnNotNullable.class)
+
+ // Migration of FK in ACTIVE_RULE_PARAMETERS to ACTIVE_RULES
+ .add(3509, "Add 'active_rule_uuid' column on 'ACTIVE_RULE_PARAMETERS' table", AddActiveRuleUuidColumnToActiveRuleParameters.class)
+ .add(3510, "Populate 'active_rule_uuid' for 'ACTIVE_RULE_PARAMETERS'", PopulateActiveRuleParametersActiveRuleUuid.class)
+ .add(3511, "Make 'active_rule_uuid' column not nullable for 'ACTIVE_RULE_PARAMETERS'", MakeActiveRuleParametersActiveRuleUuidNotNullable.class)
+ .add(3512, "Drop index on 'active_rule_id' column of 'ACTIVE_RULE_PARAMETERS' table", DropIndexOnActiveRuleIdOfActiveRuleParametersTable.class)
+ .add(3513, "Add index on 'active_rule_uuid' column of 'ACTIVE_RULE_PARAMETERS' table", AddIndexOnActiveRuleUuidOfActiveRuleParametersTable.class)
+
+ // Finish migration of ACTIVE_RULES
+ .add(3514, "Drop primary key on 'ID' column of 'ACTIVE_RULES' table", DropPrimaryKeyOnIdColumnOfActiveRulesTable.class)
+ .add(3515, "Add primary key on 'UUID' column of 'ACTIVE_RULES' table", AddPrimaryKeyOnUuidColumnOfActiveRulesTable.class)
+ .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)
;
}
--- /dev/null
+/*
+ * 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.activerules;
+
+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 AddActiveRuleUuidColumnToActiveRuleParameters extends DdlChange {
+ private static final String TABLE = "active_rule_parameters";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("active_rule_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddActiveRuleUuidColumnToActiveRuleParameters(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexOnActiveRuleUuidOfActiveRuleParametersTable extends DdlChange {
+ private static final String TABLE_NAME = "active_rule_parameters";
+ private static final String INDEX_NAME = "arp_active_rule_uuid";
+
+ public AddIndexOnActiveRuleUuidOfActiveRuleParametersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (!indexExists()) {
+ context.execute(new CreateIndexBuilder()
+ .setUnique(false)
+ .setTable(TABLE_NAME)
+ .setName(INDEX_NAME)
+ .addColumn(newVarcharColumnDefBuilder()
+ .setColumnName("active_rule_uuid")
+ .setIsNullable(false)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build())
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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 AddPrimaryKeyOnUuidColumnOfActiveRulesTable extends DdlChange {
+
+ public AddPrimaryKeyOnUuidColumnOfActiveRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddPrimaryKeyBuilder("active_rules", "uuid").build());
+ }
+
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable;
+
+public class AddUuidColumnToActiveRulesTable extends AddUuidColumnToTable {
+ private static final String TABLE = "active_rules";
+
+ public AddUuidColumnToActiveRulesTable(Database db) {
+ super(db, TABLE);
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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 DropActiveRuleIdColumnOfActiveRuleParametersTable extends DdlChange {
+ public DropActiveRuleIdColumnOfActiveRuleParametersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "active_rule_parameters", "active_rule_id").build());
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.DropIdColumn;
+
+public class DropIdColumnOfActiveRulesTable extends DropIdColumn {
+ private static final String TABLE = "active_rules";
+
+ public DropIdColumnOfActiveRulesTable(Database db) {
+ super(db, TABLE);
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIndexOnActiveRuleIdOfActiveRuleParametersTable extends DdlChange {
+ private static final String TABLE_NAME = "active_rule_parameters";
+ private static final String INDEX_NAME = "ix_arp_on_active_rule_id";
+
+ public DropIndexOnActiveRuleIdOfActiveRuleParametersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (indexExists()) {
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable(TABLE_NAME)
+ .setName(INDEX_NAME)
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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 DropPrimaryKeyOnIdColumnOfActiveRulesTable extends DropPrimaryKeyOnIdColumn {
+ private static final String TABLE_NAME = "active_rules";
+
+ public DropPrimaryKeyOnIdColumnOfActiveRulesTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+ super(db, dropPrimaryKeySqlGenerator, TABLE_NAME);
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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 MakeActiveRuleParametersActiveRuleUuidNotNullable extends DdlChange {
+ private static final String TABLE = "active_rule_parameters";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("active_rule_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeActiveRuleParametersActiveRuleUuidNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.MakeUuidColumnNotNullable;
+
+public class MakeActiveRulesUuidColumnNotNullable extends MakeUuidColumnNotNullable {
+ private static final String TABLE = "active_rules";
+
+ public MakeActiveRulesUuidColumnNotNullable(Database db) {
+ super(db, TABLE);
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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 PopulateActiveRuleParametersActiveRuleUuid extends DataChange {
+
+ public PopulateActiveRuleParametersActiveRuleUuid(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select arp.uuid, ar.uuid " +
+ "from active_rule_parameters arp " +
+ "join active_rules ar on arp.active_rule_id = ar.id");
+
+ massUpdate.update("update active_rule_parameters set active_rule_uuid = ? where uuid = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setString(2, row.getString(1));
+ return true;
+ });
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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 PopulateActiveRulesUuid extends DataChange {
+
+ private final UuidFactory uuidFactory;
+
+ public PopulateActiveRulesUuid(Database db, UuidFactory uuidFactory) {
+ super(db);
+ this.uuidFactory = uuidFactory;
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select id from active_rules where uuid is null order by id asc");
+ massUpdate.update("update active_rules set uuid = ? where id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, uuidFactory.create());
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddActiveRuleUuidColumnToActiveRuleParametersTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddActiveRuleUuidColumnToActiveRuleParametersTest.class, "schema.sql");
+ private DdlChange underTest = new AddActiveRuleUuidColumnToActiveRuleParameters(db.database());
+
+ @Before
+ public void setup() {
+ insertActiveRuleParameter(1L);
+ insertActiveRuleParameter(2L);
+ insertActiveRuleParameter(3L);
+ }
+
+ @Test
+ public void add_active_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("active_rule_parameters", "active_rule_uuid", Types.VARCHAR, 40, true);
+
+ assertThat(db.countRowsOfTable("active_rule_parameters"))
+ .isEqualTo(3);
+ }
+
+ private void insertActiveRuleParameter(Long id) {
+ db.executeInsert("active_rule_parameters",
+ "uuid", "uuid" + id,
+ "rules_parameter_id", id,
+ "value", "value" + id,
+ "active_rule_id", id + 1);
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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;
+
+public class AddIndexOnActiveRuleUuidOfActiveRuleParametersTableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnActiveRuleUuidOfActiveRuleParametersTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddIndexOnActiveRuleUuidOfActiveRuleParametersTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertIndex("active_rule_parameters", "arp_active_rule_uuid", "active_rule_uuid");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndex("active_rule_parameters", "arp_active_rule_uuid", "active_rule_uuid");
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidColumnOfActiveRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfActiveRulesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddPrimaryKeyOnUuidColumnOfActiveRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertPrimaryKey("active_rules", "pk_active_rules", "uuid");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddUuidColumnToActiveRulesTableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToActiveRulesTableTest.class, "schema.sql");
+ private DdlChange underTest = new AddUuidColumnToActiveRulesTable(db.database());
+
+ @Before
+ public void setup() {
+ insertActiveRule(1L);
+ insertActiveRule(2L);
+ insertActiveRule(3L);
+ }
+
+ @Test
+ public void add_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("active_rules", "uuid", Types.VARCHAR, 40, true);
+
+ assertThat(db.countRowsOfTable("active_rules"))
+ .isEqualTo(3);
+ }
+
+ private void insertActiveRule(Long id) {
+ db.executeInsert("active_rules",
+ "id", id,
+ "profile_id", id + 1,
+ "rule_id", id + 2,
+ "failure_level", id + 3);
+ }
+
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropActiveRuleIdColumnOfActiveRuleParametersTableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropActiveRuleIdColumnOfActiveRuleParametersTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropActiveRuleIdColumnOfActiveRuleParametersTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertColumnDefinition("active_rule_parameters", "active_rule_id", Types.INTEGER, null, false);
+ underTest.execute();
+ db.assertColumnDoesNotExist("active_rule_parameters", "active_rule_id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropIdColumnOfActiveRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfActiveRulesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropIdColumnOfActiveRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("active_rules", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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;
+
+public class DropIndexOnActiveRuleIdOfActiveRuleParametersTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnActiveRuleIdOfActiveRuleParametersTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropIndexOnActiveRuleIdOfActiveRuleParametersTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("active_rule_parameters");
+ db.assertIndex("active_rule_parameters", "ix_arp_on_active_rule_id", "active_rule_id");
+
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("active_rule_parameters", "ix_arp_on_active_rule_id");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("active_rule_parameters", "ix_arp_on_active_rule_id");
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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.DdlChange;
+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 DropPrimaryKeyOnIdColumnOfActiveRulesTableTest {
+
+ private static final String TABLE_NAME = "active_rules";
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfActiveRulesTableTest.class, "schema.sql");
+
+ private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+
+ private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfActiveRulesTable(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);
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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 MakeActiveRuleParametersActiveRuleUuidNotNullableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeActiveRuleParametersActiveRuleUuidNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeActiveRuleParametersActiveRuleUuidNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("active_rule_parameters", "active_rule_uuid", VARCHAR, null, false);
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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 MakeActiveRulesUuidColumnNotNullableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeActiveRulesUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeActiveRulesUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_nullable() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("active_rules", "uuid", VARCHAR, null, false);
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import org.assertj.core.groups.Tuple;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateActiveRuleParametersActiveRuleUuidTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateActiveRuleParametersActiveRuleUuidTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateActiveRuleParametersActiveRuleUuid(db.database());
+
+ @Test
+ public void populate_uuids() throws SQLException {
+ insertActiveRule(1L);
+ insertActiveRule(2L);
+ insertActiveRule(3L);
+
+ insertActiveRuleParameter(4L, 1L);
+ insertActiveRuleParameter(5L, 2L);
+ insertActiveRuleParameter(6L, 3L);
+
+ underTest.execute();
+
+ assertThatTableContains(
+ tuple("uuid4", 1L, "uuid1", "value4"),
+ tuple("uuid5", 2L, "uuid2", "value5"),
+ tuple("uuid6", 3L, "uuid3", "value6")
+ );
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ insertActiveRule(1L);
+ insertActiveRule(2L);
+ insertActiveRule(3L);
+
+ insertActiveRuleParameter(4L, 1L);
+ insertActiveRuleParameter(5L, 2L);
+ insertActiveRuleParameter(6L, 3L);
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ assertThatTableContains(
+ tuple("uuid4", 1L, "uuid1", "value4"),
+ tuple("uuid5", 2L, "uuid2", "value5"),
+ tuple("uuid6", 3L, "uuid3", "value6")
+ );
+ }
+
+ private void assertThatTableContains(Tuple... tuples) {
+ List<Map<String, Object>> select = db.select("select uuid, active_rule_id, active_rule_uuid, value from active_rule_parameters");
+ assertThat(select).extracting(m -> m.get("UUID"), m -> m.get("ACTIVE_RULE_ID"), m -> m.get("ACTIVE_RULE_UUID"), m -> m.get("VALUE"))
+ .containsExactlyInAnyOrder(tuples);
+ }
+
+ private void insertActiveRule(Long id) {
+ db.executeInsert("active_rules",
+ "uuid", "uuid" + id,
+ "id", id,
+ "profile_id", id + 1,
+ "rule_id", id + 2,
+ "failure_level", id + 3);
+ }
+
+ private void insertActiveRuleParameter(Long id, Long activeRuleId) {
+ db.executeInsert("active_rule_parameters",
+ "uuid", "uuid" + id,
+ "rules_parameter_id", id,
+ "value", "value" + id,
+ "active_rule_id", activeRuleId);
+ }
+}
--- /dev/null
+/*
+ * 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.activerules;
+
+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 PopulateActiveRulesUuidTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateActiveRulesUuidTest.class, "schema.sql");
+
+ private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+ private DataChange underTest = new PopulateActiveRulesUuid(db.database(), uuidFactory);
+
+ @Test
+ public void populate_uuids() throws SQLException {
+ insertActiveRule(1L);
+ insertActiveRule(2L);
+ insertActiveRule(3L);
+
+ underTest.execute();
+
+ verifyUuidsAreNotNull();
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ insertActiveRule(1L);
+ insertActiveRule(2L);
+ insertActiveRule(3L);
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ verifyUuidsAreNotNull();
+ }
+
+ private void verifyUuidsAreNotNull() {
+ assertThat(db.select("select uuid from active_rules")
+ .stream()
+ .map(row -> row.get("UUID"))
+ .filter(Objects::isNull)
+ .collect(Collectors.toList())).isEmpty();
+ }
+
+ private void insertActiveRule(Long id) {
+ db.executeInsert("active_rules",
+ "id", id,
+ "profile_id", id + 1,
+ "rule_id", id + 2,
+ "failure_level", id + 3);
+ }
+}
private void insertFileSources(Long id) {
db.executeInsert("file_sources",
"id", id,
- "uuid", uuidFactory.create(),
"project_uuid", uuidFactory.create(),
"file_uuid", uuidFactory.create(),
"line_count", id + 1,
--- /dev/null
+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");
--- /dev/null
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+ "ACTIVE_RULE_ID" INTEGER NOT NULL,
+ "ACTIVE_RULE_UUID" VARCHAR(40) 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");
--- /dev/null
+CREATE TABLE "ACTIVE_RULES"(
+ "ID" INTEGER NOT NULL,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_ID" INTEGER NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT
+);
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_ID", "RULE_ID");
--- /dev/null
+CREATE TABLE "ACTIVE_RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "PROFILE_ID" INTEGER NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_ID", "RULE_ID");
--- /dev/null
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+ "ACTIVE_RULE_ID" INTEGER NOT NULL,
+ "ACTIVE_RULE_UUID" VARCHAR(40) 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 "ARP_ACTIVE_RULE_UUID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_UUID");
--- /dev/null
+CREATE TABLE "ACTIVE_RULES"(
+ "ID" INTEGER NOT NULL,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_ID" INTEGER NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_ID", "RULE_ID");
--- /dev/null
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+ "ACTIVE_RULE_ID" INTEGER NOT NULL,
+ "ACTIVE_RULE_UUID" VARCHAR(40) 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");
--- /dev/null
+CREATE TABLE "ACTIVE_RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_ID" INTEGER NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_ID", "RULE_ID");
--- /dev/null
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+ "ACTIVE_RULE_ID" INTEGER NOT NULL,
+ "ACTIVE_RULE_UUID" VARCHAR(40),
+ "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");
--- /dev/null
+CREATE TABLE "ACTIVE_RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40),
+ "PROFILE_ID" INTEGER NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_ID", "RULE_ID");
--- /dev/null
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+ "ACTIVE_RULE_ID" INTEGER NOT NULL,
+ "ACTIVE_RULE_UUID" VARCHAR(40),
+ "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");
+
+CREATE TABLE "ACTIVE_RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_ID" INTEGER NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_ID", "RULE_ID");
--- /dev/null
+CREATE TABLE "ACTIVE_RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40),
+ "PROFILE_ID" INTEGER NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_ID", "RULE_ID");
public static final String DOC_ID_PREFIX = "ar_";
- public ActiveRuleDoc(long id) {
+ public ActiveRuleDoc(String uuid) {
super(TYPE_ACTIVE_RULE, Maps.newHashMapWithExpectedSize(10));
- setField(FIELD_ACTIVE_RULE_ID, String.valueOf(id));
+ setField(FIELD_ACTIVE_RULE_ID, uuid);
}
public ActiveRuleDoc(Map<String, Object> source) {
return DOC_ID_PREFIX + activeRuleId;
}
- public static long activeRuleIdOf(String docId) {
+ public static String activeRuleIdOf(String docId) {
if (docId.startsWith(DOC_ID_PREFIX)) {
- return Long.valueOf(docId.substring(DOC_ID_PREFIX.length()));
+ return docId.substring(DOC_ID_PREFIX.length());
}
// support for old active rule docId
- return Long.valueOf(docId);
+ return docId;
}
@Override
public void commitAndIndex(DbSession dbSession, Collection<ActiveRuleChange> changes) {
List<EsQueueDto> items = changes.stream()
.map(ActiveRuleChange::getActiveRule)
- .map(ar -> newQueueDto(docIdOf(ar.getId()), ID_TYPE_ACTIVE_RULE_ID, String.valueOf(ar.getRuleId())))
+ .map(ar -> newQueueDto(docIdOf(ar.getUuid()), ID_TYPE_ACTIVE_RULE_ID, String.valueOf(ar.getRuleId())))
.collect(toArrayList());
dbClient.esQueueDao().insert(dbSession, items);
BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, listener);
bulkIndexer.start();
Map<String, EsQueueDto> remaining = new HashMap<>(activeRuleItems);
- dbClient.activeRuleDao().scrollByIdsForIndexing(dbSession, toActiveRuleIds(activeRuleItems),
+ dbClient.activeRuleDao().scrollByUuidsForIndexing(dbSession, toActiveRuleUuids(activeRuleItems),
i -> {
- remaining.remove(docIdOf(i.getId()));
+ remaining.remove(docIdOf(i.getUuid()));
bulkIndexer.add(newIndexRequest(i));
});
return bulkIndexer.stop();
}
- private static Collection<Long> toActiveRuleIds(Map<String, EsQueueDto> activeRuleItems) {
+ private static Collection<String> toActiveRuleUuids(Map<String, EsQueueDto> activeRuleItems) {
Set<String> docIds = activeRuleItems.keySet();
return docIds.stream()
.map(ActiveRuleDoc::activeRuleIdOf)
}
private static IndexRequest newIndexRequest(IndexedActiveRuleDto dto) {
- ActiveRuleDoc doc = new ActiveRuleDoc(dto.getId())
+ ActiveRuleDoc doc = new ActiveRuleDoc(dto.getUuid())
.setRuleId(dto.getRuleId())
.setRuleProfileUuid(dto.getRuleProfileUuid())
.setSeverity(SeverityUtil.getSeverityFromOrdinal(dto.getSeverity()));
commitAndIndex(rule1, ar);
- EsQueueDto expectedItem = EsQueueDto.create(TYPE_ACTIVE_RULE.format(), "ar_" + ar.getId(), "activeRuleId", valueOf(ar.getRuleId()));
+ EsQueueDto expectedItem = EsQueueDto.create(TYPE_ACTIVE_RULE.format(), "ar_" + ar.getUuid(), "activeRuleId", valueOf(ar.getRuleId()));
assertThatEsQueueContainsExactly(expectedItem);
es.unlockWrites(TYPE_ACTIVE_RULE);
}
List<String> docs = es.getIds(TYPE_ACTIVE_RULE);
assertThat(docs).hasSize(expected.length);
for (ActiveRuleDto activeRuleDto : expected) {
- assertThat(docs).contains("ar_" + activeRuleDto.getId());
+ assertThat(docs).contains("ar_" + activeRuleDto.getUuid());
}
}
private void verify(ActiveRuleDoc doc1, QProfileDto profile, ActiveRuleDto activeRule) {
assertThat(doc1)
- .matches(doc -> doc.getId().equals("ar_" + activeRule.getId()))
+ .matches(doc -> doc.getId().equals("ar_" + activeRule.getUuid()))
.matches(doc -> doc.getRuleProfileUuid().equals(profile.getRulesProfileUuid()))
.matches(doc -> doc.getSeverity().equals(activeRule.getSeverityString()));
}
}
private void register(Collection<ActiveRuleDto> activeRules, Collection<ActiveRuleParamDto> activeRuleParams) {
- ListMultimap<Integer, ActiveRuleParamDto> paramsByActiveRuleId = activeRuleParams.stream().collect(index(ActiveRuleParamDto::getActiveRuleId));
+ ListMultimap<String, ActiveRuleParamDto> paramsByActiveRuleId = activeRuleParams.stream().collect(index(ActiveRuleParamDto::getActiveRuleUuid));
for (ActiveRuleDto activeRule : activeRules) {
- ActiveRuleWrapper wrapper = new ActiveRuleWrapper(activeRule, paramsByActiveRuleId.get(activeRule.getId()));
+ ActiveRuleWrapper wrapper = new ActiveRuleWrapper(activeRule, paramsByActiveRuleId.get(activeRule.getUuid()));
this.activeRulesByKey.put(activeRule.getKey(), wrapper);
}
}
.map(QProfileDto::getRulesProfileUuid)
.collect(MoreCollectors.toHashSet());
Collection<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRulesAndRuleProfileUuids(dbSession, ruleIds, ruleProfileUuids);
- List<Integer> activeRuleIds = activeRules.stream().map(ActiveRuleDto::getId).collect(MoreCollectors.toArrayList(activeRules.size()));
- List<ActiveRuleParamDto> activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds);
+ List<String> activeRuleUuids = activeRules.stream().map(ActiveRuleDto::getUuid).collect(MoreCollectors.toArrayList(activeRules.size()));
+ List<ActiveRuleParamDto> activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids);
return new DescendantProfilesSupplier.Result(profiles, activeRules, activeRuleParams);
};
}
private void completeWithActiveRules(DbSession dbSession, RuleActivationContext.Builder builder, Collection<Integer> ruleIds, Collection<String> ruleProfileUuids) {
Collection<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRulesAndRuleProfileUuids(dbSession, ruleIds, ruleProfileUuids);
builder.setActiveRules(activeRules);
- List<Integer> activeRuleIds = activeRules.stream().map(ActiveRuleDto::getId).collect(MoreCollectors.toArrayList(activeRules.size()));
- builder.setActiveRuleParams(db.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds));
+ List<String> activeRuleUuids = activeRules.stream().map(ActiveRuleDto::getUuid).collect(MoreCollectors.toArrayList(activeRules.size()));
+ builder.setActiveRuleParams(db.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids));
}
private static boolean isSame(ActiveRuleChange change, ActiveRuleWrapper activeRule) {
private void verifyActiveRuleInDb(QProfileDto profile, RuleDefinitionDto rule, String expectedSeverity) {
ActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByKey(dbSession, ActiveRuleKey.of(profile, rule.getKey())).get();
- assertThat(activeRule.getId()).isPositive();
+ assertThat(activeRule.getUuid()).isNotNull();
assertThat(activeRule.getInheritance()).isNull();
assertThat(activeRule.doesOverride()).isFalse();
assertThat(activeRule.getRuleId()).isEqualTo(rule.getId());
assertThat(activeRule.getCreatedAt()).isPositive();
assertThat(activeRule.getUpdatedAt()).isPositive();
- List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRule.getId());
+ List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid());
assertThat(params).isEmpty();
QProfileChangeQuery changeQuery = new QProfileChangeQuery(profile.getKee());
assertThat(activeRule.getCreatedAt()).isNotNull();
assertThat(activeRule.getUpdatedAt()).isNotNull();
- List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId());
+ List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
assertThat(params).hasSize(expectedParams.size());
if (changes != null) {
ActiveRuleChange change = changes.stream()
- .filter(c -> c.getActiveRule().getId().equals(activeRule.getId()))
+ .filter(c -> c.getActiveRule().getUuid().equals(activeRule.getUuid()))
.findFirst().orElseThrow(IllegalStateException::new);
assertThat(change.getInheritance()).isEqualTo(expectedInheritance);
assertThat(change.getSeverity()).isEqualTo(expectedSeverity);
}
private static void assertThatRuleHasParams(DbTester db, ActiveRuleDto activeRule, Tuple... expectedParams) {
- assertThat(db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId()))
+ assertThat(db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid()))
.extracting(ActiveRuleParamDto::getKey, ActiveRuleParamDto::getValue)
.containsExactlyInAnyOrder(expectedParams);
}
private void compareActivationParams(DbSession session, ActiveRuleDto leftRule, ActiveRuleDto rightRule, QProfileComparisonResult result) {
RuleKey key = leftRule.getRuleKey();
- Map<String, String> leftParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleId(session, leftRule.getId()));
- Map<String, String> rightParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleId(session, rightRule.getId()));
+ Map<String, String> leftParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleUuid(session, leftRule.getUuid()));
+ Map<String, String> rightParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleUuid(session, rightRule.getUuid()));
if (leftParams.equals(rightParams) && leftRule.getSeverityString().equals(rightRule.getSeverityString())) {
result.same.put(key, leftRule);
} else {
private RulesProfile wrap(DbSession dbSession, QProfileDto profile) {
RulesProfile target = new RulesProfile(profile.getName(), profile.getLanguage());
List<OrgActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByProfile(dbSession, profile);
- List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, Lists.transform(activeRuleDtos, ActiveRuleDto::getId));
- ListMultimap<Integer, ActiveRuleParamDto> activeRuleParamsByActiveRuleId = FluentIterable.from(activeRuleParamDtos).index(ActiveRuleParamDto::getActiveRuleId);
+ List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, Lists.transform(activeRuleDtos, ActiveRuleDto::getUuid));
+ ListMultimap<String, ActiveRuleParamDto> activeRuleParamsByActiveRuleUuid = FluentIterable.from(activeRuleParamDtos).index(ActiveRuleParamDto::getActiveRuleUuid);
for (ActiveRuleDto activeRule : activeRuleDtos) {
// TODO all rules should be loaded by using one query with all active rule keys as parameter
Rule rule = ruleFinder.findByKey(activeRule.getRuleKey());
org.sonar.api.rules.ActiveRule wrappedActiveRule = target.activateRule(rule, RulePriority.valueOf(activeRule.getSeverityString()));
- List<ActiveRuleParamDto> paramDtos = activeRuleParamsByActiveRuleId.get(activeRule.getId());
+ List<ActiveRuleParamDto> paramDtos = activeRuleParamsByActiveRuleUuid.get(activeRule.getUuid());
for (ActiveRuleParamDto activeRuleParamDto : paramDtos) {
wrappedActiveRule.setParameter(activeRuleParamDto.getKey(), activeRuleParamDto.getValue());
}
@Override
public List<ActiveRuleChange> deleteRule(DbSession dbSession, RuleDefinitionDto rule) {
List<ActiveRuleChange> changes = new ArrayList<>();
- List<Integer> activeRuleIds = new ArrayList<>();
+ List<String> activeRuleUuids = new ArrayList<>();
db.activeRuleDao().selectByRuleIdOfAllOrganizations(dbSession, rule.getId()).forEach(ar -> {
- activeRuleIds.add(ar.getId());
+ activeRuleUuids.add(ar.getUuid());
changes.add(new ActiveRuleChange(ActiveRuleChange.Type.DEACTIVATED, ar, rule));
});
- db.activeRuleDao().deleteByIds(dbSession, activeRuleIds);
- db.activeRuleDao().deleteParamsByActiveRuleIds(dbSession, activeRuleIds);
+ db.activeRuleDao().deleteByUuids(dbSession, activeRuleUuids);
+ db.activeRuleDao().deleteParamsByActiveRuleUuids(dbSession, activeRuleUuids);
return changes;
}
private Multimap<ActiveRuleDto, ActiveRuleParamDto> getActiveRuleParamsByActiveRule(DbSession dbSession, OrganizationDto organization, RuleDto customRule) {
List<OrgActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRuleId(dbSession, organization, customRule.getId());
- Map<Integer, OrgActiveRuleDto> activeRuleById = from(activeRuleDtos).uniqueIndex(ActiveRuleDto::getId);
- List<Integer> activeRuleIds = Lists.transform(activeRuleDtos, ActiveRuleDto::getId);
- List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds);
+ Map<String, OrgActiveRuleDto> activeRuleByUuid = from(activeRuleDtos).uniqueIndex(ActiveRuleDto::getUuid);
+ List<String> activeRuleUuids = Lists.transform(activeRuleDtos, ActiveRuleDto::getUuid);
+ List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids);
return from(activeRuleParamDtos)
- .index(new ActiveRuleParamToActiveRule(activeRuleById));
+ .index(new ActiveRuleParamToActiveRule(activeRuleByUuid));
}
private void deleteOrUpdateParameters(DbSession dbSession, RuleUpdate update, RuleDto customRule, List<String> paramKeys,
}
private static class ActiveRuleParamToActiveRule implements Function<ActiveRuleParamDto, ActiveRuleDto> {
- private final Map<Integer, OrgActiveRuleDto> activeRuleById;
+ private final Map<String, OrgActiveRuleDto> activeRuleByUuid;
- private ActiveRuleParamToActiveRule(Map<Integer, OrgActiveRuleDto> activeRuleById) {
- this.activeRuleById = activeRuleById;
+ private ActiveRuleParamToActiveRule(Map<String, OrgActiveRuleDto> activeRuleByUuid) {
+ this.activeRuleByUuid = activeRuleByUuid;
}
@Override
public OrgActiveRuleDto apply(@Nonnull ActiveRuleParamDto input) {
- return activeRuleById.get(input.getActiveRuleId());
+ return activeRuleByUuid.get(input.getActiveRuleUuid());
}
}
@Override
public void accept(@Nonnull ActiveRuleParamDto activeRuleParamDto) {
if (activeRuleParamDto.getKey().equals(key)) {
- dbClient.activeRuleDao().deleteParamById(dbSession, activeRuleParamDto.getUuid());
+ dbClient.activeRuleDao().deleteParamByUuid(dbSession, activeRuleParamDto.getUuid());
}
}
}
}
private ListMultimap<ActiveRuleKey, ActiveRuleParamDto> loadParams(DbSession dbSession, List<OrgActiveRuleDto> activeRules) {
- Map<Integer, ActiveRuleKey> activeRuleIdsByKey = new HashMap<>();
+ Map<String, ActiveRuleKey> activeRuleUuidsByKey = new HashMap<>();
for (OrgActiveRuleDto activeRule : activeRules) {
- activeRuleIdsByKey.put(activeRule.getId(), activeRule.getKey());
+ activeRuleUuidsByKey.put(activeRule.getUuid(), activeRule.getKey());
}
- List<ActiveRuleParamDto> activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, Lists.transform(activeRules, ActiveRuleDto::getId));
+ List<ActiveRuleParamDto> activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, Lists.transform(activeRules, ActiveRuleDto::getUuid));
ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = ArrayListMultimap.create(activeRules.size(), 10);
for (ActiveRuleParamDto activeRuleParam : activeRuleParams) {
- ActiveRuleKey activeRuleKey = activeRuleIdsByKey.get(activeRuleParam.getActiveRuleId());
+ ActiveRuleKey activeRuleKey = activeRuleUuidsByKey.get(activeRuleParam.getActiveRuleUuid());
activeRuleParamsByActiveRuleKey.put(activeRuleKey, activeRuleParam);
}
List<Rules.Active> completeShow(DbSession dbSession, OrganizationDto organization, RuleDefinitionDto rule) {
List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByRuleId(dbSession, organization, rule.getId());
- Map<Integer, ActiveRuleKey> activeRuleIdsByKey = new HashMap<>();
+ Map<String, ActiveRuleKey> activeRuleUuidsByKey = new HashMap<>();
for (OrgActiveRuleDto activeRuleDto : activeRules) {
- activeRuleIdsByKey.put(activeRuleDto.getId(), activeRuleDto.getKey());
+ activeRuleUuidsByKey.put(activeRuleDto.getUuid(), activeRuleDto.getKey());
}
- List<Integer> activeRuleIds = activeRules.stream().map(ActiveRuleDto::getId).collect(Collectors.toList());
- List<ActiveRuleParamDto> activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds);
+ List<String> activeRuleUuids = activeRules.stream().map(ActiveRuleDto::getUuid).collect(Collectors.toList());
+ List<ActiveRuleParamDto> activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids);
ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = ArrayListMultimap.create(activeRules.size(), 10);
for (ActiveRuleParamDto activeRuleParamDto : activeRuleParams) {
- ActiveRuleKey activeRuleKey = activeRuleIdsByKey.get(activeRuleParamDto.getActiveRuleId());
+ ActiveRuleKey activeRuleKey = activeRuleUuidsByKey.get(activeRuleParamDto.getActiveRuleUuid());
activeRuleParamsByActiveRuleKey.put(activeRuleKey, activeRuleParamDto);
}
ActiveRuleDto activeRule = db.qualityProfiles().activateRule(profile, rule);
ActiveRuleParamDto dto = ActiveRuleParamDto.createFor(param)
.setValue("20")
- .setActiveRuleId(activeRule.getId());
+ .setActiveRuleUuid(activeRule.getUuid());
db.getDbClient().activeRuleDao().insertParam(db.getSession(), activeRule, dto);
return activeRule;
}
assertThat(activeRule.getCreatedAt()).isNotNull();
assertThat(activeRule.getUpdatedAt()).isNotNull();
- List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId());
+ List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
assertThat(params).hasSize(expectedParams.size());
if (changes != null) {
ActiveRuleChange change = changes.stream()
- .filter(c -> c.getActiveRule().getId().equals(activeRule.getId()))
+ .filter(c -> c.getActiveRule().getUuid().equals(activeRule.getUuid()))
.findFirst().orElseThrow(IllegalStateException::new);
assertThat(change.getInheritance()).isEqualTo(expectedInheritance);
assertThat(change.getSeverity()).isEqualTo(expectedSeverity);
assertThat(activeRule.getCreatedAt()).isNotNull();
assertThat(activeRule.getUpdatedAt()).isNotNull();
- List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId());
+ List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
assertThat(params).hasSize(expectedParams.size());
}
assertThat(activeRule.getCreatedAt()).isNotNull();
assertThat(activeRule.getUpdatedAt()).isNotNull();
- List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId());
+ List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
assertThat(params).hasSize(expectedParams.size());
if (changes != null) {
ActiveRuleChange change = changes.stream()
- .filter(c -> c.getActiveRule().getId().equals(activeRule.getId()))
+ .filter(c -> c.getActiveRule().getUuid().equals(activeRule.getUuid()))
.findFirst().orElseThrow(IllegalStateException::new);
assertThat(change.getInheritance()).isEqualTo(expectedInheritance);
assertThat(change.getSeverity()).isEqualTo(expectedSeverity);
assertThat(activeRule.getCreatedAt()).isNotNull();
assertThat(activeRule.getUpdatedAt()).isNotNull();
- List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId());
+ List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
assertThat(params).hasSize(expectedParams.size());
}
.setSeverity(Severity.BLOCKER);
db.getDbClient().activeRuleDao().insert(dbSession, activeRuleDto);
db.getDbClient().activeRuleDao().insertParam(dbSession, activeRuleDto, new ActiveRuleParamDto()
- .setActiveRuleId(activeRuleDto.getId())
+ .setActiveRuleUuid(activeRuleDto.getUuid())
.setRulesParameterId(ruleParam1.getId())
.setKey(ruleParam1.getName())
.setValue(ruleParam1.getDefaultValue()));
assertThat(activeRuleReloaded.getSeverityString()).isEqualTo(Severity.BLOCKER);
// Verify active rule parameters has been updated
- List<ActiveRuleParamDto> activeRuleParams = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleReloaded.getId());
+ List<ActiveRuleParamDto> activeRuleParams = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(dbSession, activeRuleReloaded.getUuid());
assertThat(activeRuleParams).hasSize(2);
Map<String, ActiveRuleParamDto> activeRuleParamsByKey = ActiveRuleParamDto.groupByKey(activeRuleParams);