From: Duarte Meneses Date: Wed, 22 Apr 2020 20:24:42 +0000 (-0500) Subject: SONAR-13240 Change PK of ACTIVE_RULES and update FK X-Git-Tag: 8.4.0.35506~172 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=34d010c997b9829a3b1e62344b907b445166fa79;p=sonarqube.git SONAR-13240 Change PK of ACTIVE_RULES and update FK --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java index 879a72ab987..68e156594d0 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java @@ -100,7 +100,9 @@ public class ActiveRuleDao implements Dao { 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; } @@ -108,7 +110,7 @@ public class ActiveRuleDao implements Dao { 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; } @@ -116,8 +118,8 @@ public class ActiveRuleDao implements Dao { public Optional delete(DbSession dbSession, ActiveRuleKey key) { Optional 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; } @@ -127,9 +129,9 @@ public class ActiveRuleDao implements Dao { DatabaseUtils.executeLargeUpdates(rulesProfileUuids, mapper::deleteByRuleProfileUuids); } - public void deleteByIds(DbSession dbSession, List activeRuleIds) { + public void deleteByUuids(DbSession dbSession, List activeRuleUuids) { ActiveRuleMapper mapper = mapper(dbSession); - DatabaseUtils.executeLargeUpdates(activeRuleIds, mapper::deleteByIds); + DatabaseUtils.executeLargeUpdates(activeRuleUuids, mapper::deleteByUuids); } public void deleteParametersByRuleProfileUuids(DbSession dbSession, Collection rulesProfileUuids) { @@ -140,20 +142,20 @@ public class ActiveRuleDao implements Dao { /** * Nested DTO ActiveRuleParams */ - public List selectParamsByActiveRuleId(DbSession dbSession, Integer activeRuleId) { - return mapper(dbSession).selectParamsByActiveRuleId(activeRuleId); + public List selectParamsByActiveRuleUuid(DbSession dbSession, String activeRuleUuid) { + return mapper(dbSession).selectParamsByActiveRuleUuid(activeRuleUuid); } - public List selectParamsByActiveRuleIds(final DbSession dbSession, List activeRuleIds) { - return executeLargeInputs(activeRuleIds, mapper(dbSession)::selectParamsByActiveRuleIds); + public List selectParamsByActiveRuleUuids(final DbSession dbSession, List 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; @@ -166,17 +168,17 @@ public class ActiveRuleDao implements Dao { 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 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); } @@ -184,9 +186,9 @@ public class ActiveRuleDao implements Dao { } } - public void deleteParamsByActiveRuleIds(DbSession dbSession, List activeRuleIds) { + public void deleteParamsByActiveRuleUuids(DbSession dbSession, List activeRuleUuids) { ActiveRuleMapper mapper = mapper(dbSession); - DatabaseUtils.executeLargeUpdates(activeRuleIds, mapper::deleteParamsByActiveRuleIds); + DatabaseUtils.executeLargeUpdates(activeRuleUuids, mapper::deleteParamsByActiveRuleUuids); } public Map countActiveRulesByQuery(DbSession dbSession, ActiveRuleCountQuery query) { @@ -201,11 +203,11 @@ public class ActiveRuleDao implements Dao { }); } - public void scrollByIdsForIndexing(DbSession dbSession, Collection ids, Consumer consumer) { + public void scrollByUuidsForIndexing(DbSession dbSession, Collection uuids, Consumer consumer) { ActiveRuleMapper mapper = mapper(dbSession); - executeLargeInputsWithoutOutput(ids, + executeLargeInputsWithoutOutput(uuids, pageOfIds -> mapper - .scrollByIdsForIndexing(pageOfIds, context -> { + .scrollByUuidsForIndexing(pageOfIds, context -> { IndexedActiveRuleDto dto = context.getResultObject(); consumer.accept(dto); })); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java index 44eb58b943e..6cc8c2efb22 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java @@ -36,7 +36,7 @@ public class ActiveRuleDto { 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; @@ -66,12 +66,12 @@ public class ActiveRuleDto { 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; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java index d159244eb82..36b75922667 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java @@ -34,11 +34,11 @@ public interface ActiveRuleMapper { void update(ActiveRuleDto dto); - void delete(int activeRuleId); + void delete(String activeRuleUuid); void deleteByRuleProfileUuids(@Param("rulesProfileUuids") Collection rulesProfileUuids); - void deleteByIds(@Param("ids") Collection ids); + void deleteByUuids(@Param("uuids") Collection uuids); @CheckForNull ActiveRuleDto selectByKey(@Param("ruleProfileUuid") String ruleProfileUuid, @Param("repository") String repository, @Param("rule") String rule); @@ -65,24 +65,24 @@ public interface ActiveRuleMapper { void updateParameter(ActiveRuleParamDto dto); - void deleteParameters(int activeRuleId); + void deleteParameters(String activeRuleUuid); void deleteParametersByRuleProfileUuids(@Param("rulesProfileUuids") Collection rulesProfileUuids); void deleteParameter(String activeRuleParamUuid); - void deleteParamsByActiveRuleIds(@Param("activeRuleIds") Collection activeRuleIds); + void deleteParamsByActiveRuleUuids(@Param("activeRuleUuids") Collection activeRuleUuids); - List selectParamsByActiveRuleId(int activeRuleId); + List selectParamsByActiveRuleUuid(String activeRuleUuid); - List selectParamsByActiveRuleIds(@Param("ids") List ids); + List selectParamsByActiveRuleUuids(@Param("uuids") List uuids); List countActiveRulesByQuery(@Param("organizationUuid") String organizationUuid, @Param("profileUuids") List profileUuids, @Nullable @Param("ruleStatus") RuleStatus ruleStatus, @Param("inheritance") String inheritance); void scrollAllForIndexing(ResultHandler handler); - void scrollByIdsForIndexing(@Param("ids") Collection ids, ResultHandler handler); + void scrollByUuidsForIndexing(@Param("uuids") Collection uuids, ResultHandler handler); void scrollByRuleProfileUuidForIndexing(@Param("ruleProfileUuid") String ruleProfileUuid, ResultHandler handler); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleParamDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleParamDto.java index 64e61e9524b..c42c89923a4 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleParamDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleParamDto.java @@ -30,7 +30,7 @@ import org.sonar.db.rule.RuleParamDto; public class ActiveRuleParamDto { private String uuid; - private Integer activeRuleId; + private String activeRuleUuid; private Integer rulesParameterId; private String kee; private String value; @@ -44,12 +44,12 @@ public class ActiveRuleParamDto { 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; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ExportRuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ExportRuleDto.java index 4204541971c..16dc196df7a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ExportRuleDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ExportRuleDto.java @@ -26,7 +26,7 @@ import org.sonar.api.rules.RuleType; 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; @@ -43,8 +43,8 @@ public class ExportRuleDto { return template != null; } - public Integer getActiveRuleId() { - return activeRuleId; + public String getActiveRuleUuid() { + return activeRuleUuid; } public RuleKey getRuleKey() { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ExportRuleParamDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ExportRuleParamDto.java index b0f54e5c6c2..032fb2ca9c9 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ExportRuleParamDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ExportRuleParamDto.java @@ -20,12 +20,12 @@ 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() { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java index 480522d3764..d953b8e6fc3 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java @@ -22,7 +22,7 @@ package org.sonar.db.qualityprofile; import javax.annotation.CheckForNull; public class IndexedActiveRuleDto { - private long id; + private String uuid; private int ruleId; private int severity; private String inheritance; @@ -30,8 +30,8 @@ public class IndexedActiveRuleDto { private String key; private String ruleProfileUuid; - public long getId() { - return id; + public String getUuid() { + return uuid; } public int getRuleId() { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileExportDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileExportDao.java index c811d7ae0b1..c1d15383be6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileExportDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileExportDao.java @@ -33,17 +33,17 @@ public class QualityProfileExportDao implements Dao { public List selectRulesByProfile(DbSession dbSession, QProfileDto profile) { List exportRules = mapper(dbSession).selectByProfileUuid(profile.getKee()); - Map exportRulesById = exportRules.stream().collect(Collectors.toMap(ExportRuleDto::getActiveRuleId, x -> x)); - Map> rulesParams = selectParamsByActiveRuleIds(dbSession, exportRulesById.keySet()); + Map exportRulesByUuid = exportRules.stream().collect(Collectors.toMap(ExportRuleDto::getActiveRuleUuid, x -> x)); + Map> 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> selectParamsByActiveRuleIds(DbSession dbSession, Collection activeRuleIds) { - return executeLargeInputs(activeRuleIds, ids -> mapper(dbSession).selectParamsByActiveRuleIds(ids)) + private static Map> selectParamsByActiveRuleUuids(DbSession dbSession, Collection 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) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileExportMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileExportMapper.java index 5fa06450a3c..2f4a48ac1c0 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileExportMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileExportMapper.java @@ -26,5 +26,5 @@ import org.apache.ibatis.annotations.Param; public interface QualityProfileExportMapper { List selectByProfileUuid(String uuid); - List selectParamsByActiveRuleIds(@Param("activeRuleIds") Collection activeRuleIds); + List selectParamsByActiveRuleUuids(@Param("activeRuleUuids") Collection activeRuleUuids); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml index 515cbe79661..7649914ce45 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml @@ -4,7 +4,7 @@ - a.id, + a.uuid, a.profile_id as "profileId", a.rule_id as "ruleId", a.failure_level as "severity", @@ -17,7 +17,7 @@ - a.id, + a.uuid, a.profile_id as "profileId", a.rule_id as "ruleId", a.failure_level as "severity", @@ -37,8 +37,9 @@ inner join rules r on r.id = a.rule_id - + insert into active_rules ( + uuid, profile_id, rule_id, failure_level, @@ -46,6 +47,7 @@ created_at, updated_at ) values ( + #{uuid, jdbcType=VARCHAR}, #{profileId, jdbcType=BIGINT}, #{ruleId, jdbcType=BIGINT}, #{severity, jdbcType=INTEGER}, @@ -62,13 +64,13 @@ inheritance = #{inheritance, jdbcType=VARCHAR}, updated_at = #{updatedAt, jdbcType=BIGINT} where - id = #{id, jdbcType=BIGINT} + uuid = #{uuid, jdbcType=BIGINT} - + delete from active_rules where - id=#{id, jdbcType=BIGINT} + uuid=#{uuid, jdbcType=BIGINT} @@ -82,11 +84,11 @@ ) - + delete from active_rules where - id in - #{id, jdbcType=INTEGER} + uuid in + #{uuid, jdbcType=VARCHAR} + - select from active_rule_parameters p - - p.active_rule_id=#{id, jdbcType=BIGINT} + + p.active_rule_uuid=#{uuid, jdbcType=VARCHAR} - - where ar.id in - #{id, jdbcType=BIGINT} + where ar.uuid in + #{uuid, jdbcType=VARCHAR} - select from active_rule_parameters p - p.active_rule_id in #{activeRuleId,jdbcType=INTEGER} + p.active_rule_uuid in #{activeRuleUuid,jdbcType=VARCHAR} diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 0c8f91f99b2..98df38e2973 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -14,25 +14,25 @@ CREATE TABLE "SCHEMA_MIGRATIONS"( ); 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"( diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java index 805cf94307f..418fc1b8efb 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java @@ -241,13 +241,13 @@ public class ActiveRuleDaoTest { // 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())); @@ -268,7 +268,7 @@ public class ActiveRuleDaoTest { 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()); @@ -287,7 +287,7 @@ public class ActiveRuleDaoTest { } @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"); @@ -295,11 +295,11 @@ public class ActiveRuleDaoTest { } @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 @@ -322,7 +322,7 @@ public class ActiveRuleDaoTest { 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()); @@ -337,7 +337,7 @@ public class ActiveRuleDaoTest { 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 @@ -345,7 +345,7 @@ public class ActiveRuleDaoTest { 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 @@ -353,7 +353,7 @@ public class ActiveRuleDaoTest { 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 @@ -402,19 +402,19 @@ public class ActiveRuleDaoTest { 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); } @@ -433,7 +433,7 @@ public class ActiveRuleDaoTest { underTest.insertParam(dbSession, activeRule, activeRuleParam2); dbSession.commit(); - assertThat(underTest.selectParamsByActiveRuleId(dbSession, activeRule.getId())).hasSize(2); + assertThat(underTest.selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid())).hasSize(2); } @Test @@ -448,7 +448,7 @@ public class ActiveRuleDaoTest { 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 @@ -459,12 +459,12 @@ public class ActiveRuleDaoTest { ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(rule1Param1).setValue("foo"); underTest.insertParam(dbSession, activeRule, activeRuleParam); - List reloaded = underTest.selectParamsByActiveRuleId(dbSession, activeRule.getId()); + List 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")); } @@ -475,7 +475,7 @@ public class ActiveRuleDaoTest { thrown.expectMessage("ActiveRule is not persisted"); underTest.insertParam(dbSession, - createFor(profile1, rule1).setId(null), + createFor(profile1, rule1).setUuid(null), ActiveRuleParamDto.createFor(rule1Param1).setValue("activeValue1")); } @@ -485,17 +485,17 @@ public class ActiveRuleDaoTest { 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)); } @@ -508,12 +508,12 @@ public class ActiveRuleDaoTest { underTest.updateParam(dbSession, activeRuleParam.setValue("bar")); - List reloaded = underTest.selectParamsByActiveRuleId(dbSession, activeRule.getId()); + List 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")); } @@ -527,7 +527,7 @@ public class ActiveRuleDaoTest { underTest.deleteParam(dbSession, param); - assertThat(underTest.selectParamsByActiveRuleId(dbSession, activeRule.getId())).hasSize(0); + assertThat(underTest.selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid())).hasSize(0); } @Test @@ -543,8 +543,8 @@ public class ActiveRuleDaoTest { 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")); } @@ -558,7 +558,7 @@ public class ActiveRuleDaoTest { underTest.deleteParametersByRuleProfileUuids(dbSession, emptyList()); - assertThat(underTest.selectParamsByActiveRuleId(dbSession, activeRuleInProfile1.getId())) + assertThat(underTest.selectParamsByActiveRuleUuid(dbSession, activeRuleInProfile1.getUuid())) .hasSize(1); } @@ -574,12 +574,12 @@ public class ActiveRuleDaoTest { ActiveRuleParamDto activeRuleParam2 = ActiveRuleParamDto.createFor(rule1Param1).setValue("bar"); underTest.insertParam(dbSession, activeRule2, activeRuleParam2); - List activeRuleIds = asList(activeRule1.getId(), activeRule2.getId()); - assertThat(underTest.selectParamsByActiveRuleIds(dbSession, activeRuleIds)).hasSize(2); + List 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 @@ -592,10 +592,10 @@ public class ActiveRuleDaoTest { 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 @@ -678,14 +678,14 @@ public class ActiveRuleDaoTest { 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 @@ -695,14 +695,14 @@ public class ActiveRuleDaoTest { 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 @@ -714,11 +714,11 @@ public class ActiveRuleDaoTest { 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 { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java index 5e92fcc0313..ab01c620b85 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java @@ -136,8 +136,8 @@ public class QualityProfileExportDaoTest { List results = underTest.selectRulesByProfile(dbSession, profile); assertThat(results) - .extracting("activeRuleId") - .containsOnly(activatedRule.getId()); + .extracting("activeRuleUuid") + .containsOnly(activatedRule.getUuid()); assertThat(results.get(0).getParams()) .extracting("key") @@ -169,32 +169,32 @@ public class QualityProfileExportDaoTest { List 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 results) { - Optional found = results.stream().filter(exportRuleDto -> id.equals(exportRuleDto.getActiveRuleId())).findFirst(); + private ExportRuleDto findExportedRuleByUuid(String uuid, List results) { + Optional found = results.stream().filter(exportRuleDto -> uuid.equals(exportRuleDto.getActiveRuleUuid())).findFirst(); if (!found.isPresent()) { Assert.fail(); } @@ -241,7 +241,7 @@ public class QualityProfileExportDaoTest { ActiveRuleParamDto dto = ActiveRuleParamDto.createFor(ruleParamDto) .setKey(ruleParamDto.getName()) .setValue("20") - .setActiveRuleId(activeRule.getId()); + .setActiveRuleUuid(activeRule.getUuid()); db.getDbClient().activeRuleDao().insertParam(db.getSession(), activeRule, dto); }); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java index a251361c119..4e028bead2d 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java @@ -27,6 +27,18 @@ import org.sonar.server.platform.db.migration.version.v83.activeruleparameters.D 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; @@ -236,98 +248,87 @@ public class DbVersion83 implements DbVersion { .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) ; } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddActiveRuleUuidColumnToActiveRuleParameters.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddActiveRuleUuidColumnToActiveRuleParameters.java new file mode 100644 index 00000000000..7f9347d11f1 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddActiveRuleUuidColumnToActiveRuleParameters.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTable.java new file mode 100644 index 00000000000..e6f532b6a26 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTable.java @@ -0,0 +1,61 @@ +/* + * 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); + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddPrimaryKeyOnUuidColumnOfActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddPrimaryKeyOnUuidColumnOfActiveRulesTable.java new file mode 100644 index 00000000000..3aaee464c4e --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddPrimaryKeyOnUuidColumnOfActiveRulesTable.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddUuidColumnToActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddUuidColumnToActiveRulesTable.java new file mode 100644 index 00000000000..721d830a5d4 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddUuidColumnToActiveRulesTable.java @@ -0,0 +1,31 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropActiveRuleIdColumnOfActiveRuleParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropActiveRuleIdColumnOfActiveRuleParametersTable.java new file mode 100644 index 00000000000..72952ee7c17 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropActiveRuleIdColumnOfActiveRuleParametersTable.java @@ -0,0 +1,36 @@ +/* + * 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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIdColumnOfActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIdColumnOfActiveRulesTable.java new file mode 100644 index 00000000000..e89cf91637a --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIdColumnOfActiveRulesTable.java @@ -0,0 +1,31 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTable.java new file mode 100644 index 00000000000..d612ae29da7 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTable.java @@ -0,0 +1,52 @@ +/* + * 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); + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTable.java new file mode 100644 index 00000000000..3c71ebaf6d0 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTable.java @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRuleParametersActiveRuleUuidNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRuleParametersActiveRuleUuidNotNullable.java new file mode 100644 index 00000000000..19ddafd1889 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRuleParametersActiveRuleUuidNotNullable.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRulesUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRulesUuidColumnNotNullable.java new file mode 100644 index 00000000000..3138410f04c --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRulesUuidColumnNotNullable.java @@ -0,0 +1,31 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRuleParametersActiveRuleUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRuleParametersActiveRuleUuid.java new file mode 100644 index 00000000000..5f71e13750a --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRuleParametersActiveRuleUuid.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRulesUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRulesUuid.java new file mode 100644 index 00000000000..613060e6456 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRulesUuid.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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; + }); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddActiveRuleUuidColumnToActiveRuleParametersTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddActiveRuleUuidColumnToActiveRuleParametersTest.java new file mode 100644 index 00000000000..2dbec7b5139 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddActiveRuleUuidColumnToActiveRuleParametersTest.java @@ -0,0 +1,61 @@ +/* + * 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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTableTest.java new file mode 100644 index 00000000000..50d2a426913 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTableTest.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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"); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddPrimaryKeyOnUuidColumnOfActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddPrimaryKeyOnUuidColumnOfActiveRulesTableTest.java new file mode 100644 index 00000000000..4901ea16618 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddPrimaryKeyOnUuidColumnOfActiveRulesTableTest.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddUuidColumnToActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddUuidColumnToActiveRulesTableTest.java new file mode 100644 index 00000000000..79911e5a627 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddUuidColumnToActiveRulesTableTest.java @@ -0,0 +1,62 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropActiveRuleIdColumnOfActiveRuleParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropActiveRuleIdColumnOfActiveRuleParametersTableTest.java new file mode 100644 index 00000000000..4976d78570e --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropActiveRuleIdColumnOfActiveRuleParametersTableTest.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIdColumnOfActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIdColumnOfActiveRulesTableTest.java new file mode 100644 index 00000000000..10c82a5d282 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIdColumnOfActiveRulesTableTest.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTableTest.java new file mode 100644 index 00000000000..76597d2ae32 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTableTest.java @@ -0,0 +1,54 @@ +/* + * 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"); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTableTest.java new file mode 100644 index 00000000000..728f6967b74 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTableTest.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRuleParametersActiveRuleUuidNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRuleParametersActiveRuleUuidNotNullableTest.java new file mode 100644 index 00000000000..ba881fb9cae --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRuleParametersActiveRuleUuidNotNullableTest.java @@ -0,0 +1,42 @@ +/* + * 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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRulesUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRulesUuidColumnNotNullableTest.java new file mode 100644 index 00000000000..a428387138e --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRulesUuidColumnNotNullableTest.java @@ -0,0 +1,42 @@ +/* + * 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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRuleParametersActiveRuleUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRuleParametersActiveRuleUuidTest.java new file mode 100644 index 00000000000..246c0ebb8d6 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRuleParametersActiveRuleUuidTest.java @@ -0,0 +1,102 @@ +/* + * 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> 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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRulesUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRulesUuidTest.java new file mode 100644 index 00000000000..f8504e8c25a --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRulesUuidTest.java @@ -0,0 +1,81 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/filesources/PopulateFileSourcesUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/filesources/PopulateFileSourcesUuidTest.java index dde090da5bc..24c48e42de0 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/filesources/PopulateFileSourcesUuidTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/filesources/PopulateFileSourcesUuidTest.java @@ -74,7 +74,6 @@ public class PopulateFileSourcesUuidTest { 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, diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddActiveRuleUuidColumnToActiveRuleParametersTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddActiveRuleUuidColumnToActiveRuleParametersTest/schema.sql new file mode 100644 index 00000000000..04d58e9edf0 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddActiveRuleUuidColumnToActiveRuleParametersTest/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "ACTIVE_RULE_PARAMETERS"( + "ACTIVE_RULE_ID" INTEGER NOT NULL, + "RULES_PARAMETER_ID" INTEGER NOT NULL, + "VALUE" VARCHAR(4000), + "RULES_PARAMETER_KEY" VARCHAR(128), + "UUID" VARCHAR(40) NOT NULL +); +ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "PK_ACTIVE_RULE_PARAMETERS" PRIMARY KEY("UUID"); +CREATE INDEX "IX_ARP_ON_ACTIVE_RULE_ID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTableTest/schema.sql new file mode 100644 index 00000000000..b074136418d --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTableTest/schema.sql @@ -0,0 +1,9 @@ +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddPrimaryKeyOnUuidColumnOfActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddPrimaryKeyOnUuidColumnOfActiveRulesTableTest/schema.sql new file mode 100644 index 00000000000..58802cb272e --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddPrimaryKeyOnUuidColumnOfActiveRulesTableTest/schema.sql @@ -0,0 +1,11 @@ +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddUuidColumnToActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddUuidColumnToActiveRulesTableTest/schema.sql new file mode 100644 index 00000000000..f7f18747670 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddUuidColumnToActiveRulesTableTest/schema.sql @@ -0,0 +1,11 @@ +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropActiveRuleIdColumnOfActiveRuleParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropActiveRuleIdColumnOfActiveRuleParametersTableTest/schema.sql new file mode 100644 index 00000000000..24d5888764c --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropActiveRuleIdColumnOfActiveRuleParametersTableTest/schema.sql @@ -0,0 +1,10 @@ +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropIdColumnOfActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropIdColumnOfActiveRulesTableTest/schema.sql new file mode 100644 index 00000000000..faf2cd098e9 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropIdColumnOfActiveRulesTableTest/schema.sql @@ -0,0 +1,12 @@ +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTableTest/schema.sql new file mode 100644 index 00000000000..fe510a7faaf --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTableTest/schema.sql @@ -0,0 +1,10 @@ +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTableTest/schema.sql new file mode 100644 index 00000000000..642bd8470a6 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTableTest/schema.sql @@ -0,0 +1,12 @@ +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRuleParametersActiveRuleUuidNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRuleParametersActiveRuleUuidNotNullableTest/schema.sql new file mode 100644 index 00000000000..0f789b84e93 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRuleParametersActiveRuleUuidNotNullableTest/schema.sql @@ -0,0 +1,10 @@ +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRulesUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRulesUuidColumnNotNullableTest/schema.sql new file mode 100644 index 00000000000..49569a9667a --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRulesUuidColumnNotNullableTest/schema.sql @@ -0,0 +1,12 @@ +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRuleParametersActiveRuleUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRuleParametersActiveRuleUuidTest/schema.sql new file mode 100644 index 00000000000..5d00ec845ca --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRuleParametersActiveRuleUuidTest/schema.sql @@ -0,0 +1,23 @@ +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRulesUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRulesUuidTest/schema.sql new file mode 100644 index 00000000000..49569a9667a --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRulesUuidTest/schema.sql @@ -0,0 +1,12 @@ +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"); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java index 2faf6a373f4..96f3266202a 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java @@ -37,9 +37,9 @@ public class ActiveRuleDoc extends BaseDoc { 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 source) { @@ -54,12 +54,12 @@ public class ActiveRuleDoc extends BaseDoc { 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 diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java index 604c4593401..2657619ff60 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java @@ -88,7 +88,7 @@ public class ActiveRuleIndexer implements ResilientIndexer { public void commitAndIndex(DbSession dbSession, Collection changes) { List 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); @@ -153,9 +153,9 @@ public class ActiveRuleIndexer implements ResilientIndexer { BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, listener); bulkIndexer.start(); Map 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)); }); @@ -166,7 +166,7 @@ public class ActiveRuleIndexer implements ResilientIndexer { return bulkIndexer.stop(); } - private static Collection toActiveRuleIds(Map activeRuleItems) { + private static Collection toActiveRuleUuids(Map activeRuleItems) { Set docIds = activeRuleItems.keySet(); return docIds.stream() .map(ActiveRuleDoc::activeRuleIdOf) @@ -214,7 +214,7 @@ public class ActiveRuleIndexer implements ResilientIndexer { } 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())); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java index 90f924bb7ef..a580c71b27d 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java @@ -122,7 +122,7 @@ public class ActiveRuleIndexerTest { 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); } @@ -196,13 +196,13 @@ public class ActiveRuleIndexerTest { List 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())); } diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java index f8892e06b22..8cc18f2713b 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java @@ -102,9 +102,9 @@ class RuleActivationContext { } private void register(Collection activeRules, Collection activeRuleParams) { - ListMultimap paramsByActiveRuleId = activeRuleParams.stream().collect(index(ActiveRuleParamDto::getActiveRuleId)); + ListMultimap 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); } } diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java index 1c98b813267..1d8b6ab8196 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java @@ -408,8 +408,8 @@ public class RuleActivator { .map(QProfileDto::getRulesProfileUuid) .collect(MoreCollectors.toHashSet()); Collection activeRules = db.activeRuleDao().selectByRulesAndRuleProfileUuids(dbSession, ruleIds, ruleProfileUuids); - List activeRuleIds = activeRules.stream().map(ActiveRuleDto::getId).collect(MoreCollectors.toArrayList(activeRules.size())); - List activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds); + List activeRuleUuids = activeRules.stream().map(ActiveRuleDto::getUuid).collect(MoreCollectors.toArrayList(activeRules.size())); + List activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids); return new DescendantProfilesSupplier.Result(profiles, activeRules, activeRuleParams); }; } @@ -423,8 +423,8 @@ public class RuleActivator { private void completeWithActiveRules(DbSession dbSession, RuleActivationContext.Builder builder, Collection ruleIds, Collection ruleProfileUuids) { Collection activeRules = db.activeRuleDao().selectByRulesAndRuleProfileUuids(dbSession, ruleIds, ruleProfileUuids); builder.setActiveRules(activeRules); - List activeRuleIds = activeRules.stream().map(ActiveRuleDto::getId).collect(MoreCollectors.toArrayList(activeRules.size())); - builder.setActiveRuleParams(db.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds)); + List 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) { diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java index d90f8c8078c..e88ed59fc79 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java @@ -173,7 +173,7 @@ public class BuiltInQProfileInsertImplTest { 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()); @@ -182,7 +182,7 @@ public class BuiltInQProfileInsertImplTest { assertThat(activeRule.getCreatedAt()).isPositive(); assertThat(activeRule.getUpdatedAt()).isPositive(); - List params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRule.getId()); + List params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid()); assertThat(params).isEmpty(); QProfileChangeQuery changeQuery = new QProfileChangeQuery(profile.getKee()); diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java index 76496951834..ec503feab87 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java @@ -357,12 +357,12 @@ public class BuiltInQProfileUpdateImplTest { assertThat(activeRule.getCreatedAt()).isNotNull(); assertThat(activeRule.getUpdatedAt()).isNotNull(); - List params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId()); + List 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); @@ -371,7 +371,7 @@ public class BuiltInQProfileUpdateImplTest { } 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); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java index b27fc4e20e0..8a3cbadc612 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java @@ -70,8 +70,8 @@ public class QProfileComparison { private void compareActivationParams(DbSession session, ActiveRuleDto leftRule, ActiveRuleDto rightRule, QProfileComparisonResult result) { RuleKey key = leftRule.getRuleKey(); - Map leftParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleId(session, leftRule.getId())); - Map rightParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleId(session, rightRule.getId())); + Map leftParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleUuid(session, leftRule.getUuid())); + Map rightParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleUuid(session, rightRule.getUuid())); if (leftParams.equals(rightParams) && leftRule.getSeverityString().equals(rightRule.getSeverityString())) { result.same.put(key, leftRule); } else { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java index 3ac3b4c3d2d..54432c9af0b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java @@ -119,14 +119,14 @@ public class QProfileExporters { private RulesProfile wrap(DbSession dbSession, QProfileDto profile) { RulesProfile target = new RulesProfile(profile.getName(), profile.getLanguage()); List activeRuleDtos = dbClient.activeRuleDao().selectByProfile(dbSession, profile); - List activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, Lists.transform(activeRuleDtos, ActiveRuleDto::getId)); - ListMultimap activeRuleParamsByActiveRuleId = FluentIterable.from(activeRuleParamDtos).index(ActiveRuleParamDto::getActiveRuleId); + List activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, Lists.transform(activeRuleDtos, ActiveRuleDto::getUuid)); + ListMultimap 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 paramDtos = activeRuleParamsByActiveRuleId.get(activeRule.getId()); + List paramDtos = activeRuleParamsByActiveRuleUuid.get(activeRule.getUuid()); for (ActiveRuleParamDto activeRuleParamDto : paramDtos) { wrappedActiveRule.setParameter(activeRuleParamDto.getKey(), activeRuleParamDto.getValue()); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java index 388c1ecf44c..9978e30fdf9 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java @@ -98,14 +98,14 @@ public class QProfileRulesImpl implements QProfileRules { @Override public List deleteRule(DbSession dbSession, RuleDefinitionDto rule) { List changes = new ArrayList<>(); - List activeRuleIds = new ArrayList<>(); + List 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; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java index 4f669fc6198..73b40ae3c4f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java @@ -230,11 +230,11 @@ public class RuleUpdater { private Multimap getActiveRuleParamsByActiveRule(DbSession dbSession, OrganizationDto organization, RuleDto customRule) { List activeRuleDtos = dbClient.activeRuleDao().selectByRuleId(dbSession, organization, customRule.getId()); - Map activeRuleById = from(activeRuleDtos).uniqueIndex(ActiveRuleDto::getId); - List activeRuleIds = Lists.transform(activeRuleDtos, ActiveRuleDto::getId); - List activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds); + Map activeRuleByUuid = from(activeRuleDtos).uniqueIndex(ActiveRuleDto::getUuid); + List activeRuleUuids = Lists.transform(activeRuleDtos, ActiveRuleDto::getUuid); + List 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 paramKeys, @@ -269,15 +269,15 @@ public class RuleUpdater { } private static class ActiveRuleParamToActiveRule implements Function { - private final Map activeRuleById; + private final Map activeRuleByUuid; - private ActiveRuleParamToActiveRule(Map activeRuleById) { - this.activeRuleById = activeRuleById; + private ActiveRuleParamToActiveRule(Map activeRuleByUuid) { + this.activeRuleByUuid = activeRuleByUuid; } @Override public OrgActiveRuleDto apply(@Nonnull ActiveRuleParamDto input) { - return activeRuleById.get(input.getActiveRuleId()); + return activeRuleByUuid.get(input.getActiveRuleUuid()); } } @@ -321,7 +321,7 @@ public class RuleUpdater { @Override public void accept(@Nonnull ActiveRuleParamDto activeRuleParamDto) { if (activeRuleParamDto.getKey().equals(key)) { - dbClient.activeRuleDao().deleteParamById(dbSession, activeRuleParamDto.getUuid()); + dbClient.activeRuleDao().deleteParamByUuid(dbSession, activeRuleParamDto.getUuid()); } } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java index 76c731213d8..3a17472127b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java @@ -126,14 +126,14 @@ public class ActiveRuleCompleter { } private ListMultimap loadParams(DbSession dbSession, List activeRules) { - Map activeRuleIdsByKey = new HashMap<>(); + Map activeRuleUuidsByKey = new HashMap<>(); for (OrgActiveRuleDto activeRule : activeRules) { - activeRuleIdsByKey.put(activeRule.getId(), activeRule.getKey()); + activeRuleUuidsByKey.put(activeRule.getUuid(), activeRule.getKey()); } - List activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, Lists.transform(activeRules, ActiveRuleDto::getId)); + List activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, Lists.transform(activeRules, ActiveRuleDto::getUuid)); ListMultimap 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); } @@ -142,16 +142,16 @@ public class ActiveRuleCompleter { List completeShow(DbSession dbSession, OrganizationDto organization, RuleDefinitionDto rule) { List activeRules = dbClient.activeRuleDao().selectByRuleId(dbSession, organization, rule.getId()); - Map activeRuleIdsByKey = new HashMap<>(); + Map activeRuleUuidsByKey = new HashMap<>(); for (OrgActiveRuleDto activeRuleDto : activeRules) { - activeRuleIdsByKey.put(activeRuleDto.getId(), activeRuleDto.getKey()); + activeRuleUuidsByKey.put(activeRuleDto.getUuid(), activeRuleDto.getKey()); } - List activeRuleIds = activeRules.stream().map(ActiveRuleDto::getId).collect(Collectors.toList()); - List activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds); + List activeRuleUuids = activeRules.stream().map(ActiveRuleDto::getUuid).collect(Collectors.toList()); + List activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids); ListMultimap 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); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java index 4249607a617..c0116aa02a2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java @@ -402,7 +402,7 @@ public class QProfileBackuperImplTest { 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; } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java index 24744f0b07b..5f58d10367c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java @@ -908,12 +908,12 @@ public class QProfileRuleImplTest { assertThat(activeRule.getCreatedAt()).isNotNull(); assertThat(activeRule.getUpdatedAt()).isNotNull(); - List params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId()); + List 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); @@ -943,7 +943,7 @@ public class QProfileRuleImplTest { assertThat(activeRule.getCreatedAt()).isNotNull(); assertThat(activeRule.getUpdatedAt()).isNotNull(); - List params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId()); + List params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid()); assertThat(params).hasSize(expectedParams.size()); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java index 91bab9c841c..4add5ec8ab8 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java @@ -221,12 +221,12 @@ public class QProfileTreeImplTest { assertThat(activeRule.getCreatedAt()).isNotNull(); assertThat(activeRule.getUpdatedAt()).isNotNull(); - List params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId()); + List 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); @@ -256,7 +256,7 @@ public class QProfileTreeImplTest { assertThat(activeRule.getCreatedAt()).isNotNull(); assertThat(activeRule.getUpdatedAt()).isNotNull(); - List params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId()); + List params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid()); assertThat(params).hasSize(expectedParams.size()); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java index 369908c5e45..4832470ba06 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java @@ -457,7 +457,7 @@ public class RuleUpdaterTest { .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())); @@ -486,7 +486,7 @@ public class RuleUpdaterTest { assertThat(activeRuleReloaded.getSeverityString()).isEqualTo(Severity.BLOCKER); // Verify active rule parameters has been updated - List activeRuleParams = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleReloaded.getId()); + List activeRuleParams = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(dbSession, activeRuleReloaded.getUuid()); assertThat(activeRuleParams).hasSize(2); Map activeRuleParamsByKey = ActiveRuleParamDto.groupByKey(activeRuleParams);