]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13240 Change PK of ACTIVE_RULES and update FK
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 22 Apr 2020 20:24:42 +0000 (15:24 -0500)
committersonartech <sonartech@sonarsource.com>
Mon, 25 May 2020 20:05:20 +0000 (20:05 +0000)
68 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleParamDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ExportRuleDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ExportRuleParamDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileExportDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileExportMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddActiveRuleUuidColumnToActiveRuleParameters.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddPrimaryKeyOnUuidColumnOfActiveRulesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddUuidColumnToActiveRulesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropActiveRuleIdColumnOfActiveRuleParametersTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIdColumnOfActiveRulesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRuleParametersActiveRuleUuidNotNullable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRulesUuidColumnNotNullable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRuleParametersActiveRuleUuid.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRulesUuid.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddActiveRuleUuidColumnToActiveRuleParametersTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddPrimaryKeyOnUuidColumnOfActiveRulesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/AddUuidColumnToActiveRulesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropActiveRuleIdColumnOfActiveRuleParametersTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIdColumnOfActiveRulesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRuleParametersActiveRuleUuidNotNullableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRulesUuidColumnNotNullableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRuleParametersActiveRuleUuidTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRulesUuidTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/filesources/PopulateFileSourcesUuidTest.java
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddActiveRuleUuidColumnToActiveRuleParametersTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddPrimaryKeyOnUuidColumnOfActiveRulesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/AddUuidColumnToActiveRulesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropActiveRuleIdColumnOfActiveRuleParametersTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropIdColumnOfActiveRulesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRuleParametersActiveRuleUuidNotNullableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/MakeActiveRulesUuidColumnNotNullableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRuleParametersActiveRuleUuidTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/activerules/PopulateActiveRulesUuidTest/schema.sql [new file with mode: 0644]
server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java
server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java

index 879a72ab987ad4111b9f67f7b21a5d3d2442d6b3..68e156594d084c680f9f2bce79a54a43502f7f90 100644 (file)
@@ -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<ActiveRuleDto> delete(DbSession dbSession, ActiveRuleKey key) {
     Optional<ActiveRuleDto> activeRule = selectByKey(dbSession, key);
     if (activeRule.isPresent()) {
-      mapper(dbSession).deleteParameters(activeRule.get().getId());
-      mapper(dbSession).delete(activeRule.get().getId());
+      mapper(dbSession).deleteParameters(activeRule.get().getUuid());
+      mapper(dbSession).delete(activeRule.get().getUuid());
     }
     return activeRule;
   }
@@ -127,9 +129,9 @@ public class ActiveRuleDao implements Dao {
     DatabaseUtils.executeLargeUpdates(rulesProfileUuids, mapper::deleteByRuleProfileUuids);
   }
 
-  public void deleteByIds(DbSession dbSession, List<Integer> activeRuleIds) {
+  public void deleteByUuids(DbSession dbSession, List<String> activeRuleUuids) {
     ActiveRuleMapper mapper = mapper(dbSession);
-    DatabaseUtils.executeLargeUpdates(activeRuleIds, mapper::deleteByIds);
+    DatabaseUtils.executeLargeUpdates(activeRuleUuids, mapper::deleteByUuids);
   }
 
   public void deleteParametersByRuleProfileUuids(DbSession dbSession, Collection<String> rulesProfileUuids) {
@@ -140,20 +142,20 @@ public class ActiveRuleDao implements Dao {
   /**
    * Nested DTO ActiveRuleParams
    */
-  public List<ActiveRuleParamDto> selectParamsByActiveRuleId(DbSession dbSession, Integer activeRuleId) {
-    return mapper(dbSession).selectParamsByActiveRuleId(activeRuleId);
+  public List<ActiveRuleParamDto> selectParamsByActiveRuleUuid(DbSession dbSession, String activeRuleUuid) {
+    return mapper(dbSession).selectParamsByActiveRuleUuid(activeRuleUuid);
   }
 
-  public List<ActiveRuleParamDto> selectParamsByActiveRuleIds(final DbSession dbSession, List<Integer> activeRuleIds) {
-    return executeLargeInputs(activeRuleIds, mapper(dbSession)::selectParamsByActiveRuleIds);
+  public List<ActiveRuleParamDto> selectParamsByActiveRuleUuids(final DbSession dbSession, List<String> activeRuleUuids) {
+    return executeLargeInputs(activeRuleUuids, mapper(dbSession)::selectParamsByActiveRuleUuids);
   }
 
   public ActiveRuleParamDto insertParam(DbSession dbSession, ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam) {
-    checkArgument(activeRule.getId() != null, ACTIVE_RULE_IS_NOT_PERSISTED);
+    checkArgument(activeRule.getUuid() != null, ACTIVE_RULE_IS_NOT_PERSISTED);
     checkArgument(activeRuleParam.getUuid() == null, ACTIVE_RULE_PARAM_IS_ALREADY_PERSISTED);
     Preconditions.checkNotNull(activeRuleParam.getRulesParameterId(), RULE_PARAM_IS_NOT_PERSISTED);
 
-    activeRuleParam.setActiveRuleId(activeRule.getId());
+    activeRuleParam.setActiveRuleUuid(activeRule.getUuid());
     activeRuleParam.setUuid(uuidFactory.create());
     mapper(dbSession).insertParameter(activeRuleParam);
     return activeRuleParam;
@@ -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<ActiveRuleDto> activeRules = selectByRuleIdOfAllOrganizations(dbSession, param.getRuleId());
     for (ActiveRuleDto activeRule : activeRules) {
-      for (ActiveRuleParamDto activeParam : selectParamsByActiveRuleId(dbSession, activeRule.getId())) {
+      for (ActiveRuleParamDto activeParam : selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid())) {
         if (activeParam.getKey().equals(param.getName())) {
           deleteParam(dbSession, activeParam);
         }
@@ -184,9 +186,9 @@ public class ActiveRuleDao implements Dao {
     }
   }
 
-  public void deleteParamsByActiveRuleIds(DbSession dbSession, List<Integer> activeRuleIds) {
+  public void deleteParamsByActiveRuleUuids(DbSession dbSession, List<String> activeRuleUuids) {
     ActiveRuleMapper mapper = mapper(dbSession);
-    DatabaseUtils.executeLargeUpdates(activeRuleIds, mapper::deleteParamsByActiveRuleIds);
+    DatabaseUtils.executeLargeUpdates(activeRuleUuids, mapper::deleteParamsByActiveRuleUuids);
   }
 
   public Map<String, Long> countActiveRulesByQuery(DbSession dbSession, ActiveRuleCountQuery query) {
@@ -201,11 +203,11 @@ public class ActiveRuleDao implements Dao {
     });
   }
 
-  public void scrollByIdsForIndexing(DbSession dbSession, Collection<Long> ids, Consumer<IndexedActiveRuleDto> consumer) {
+  public void scrollByUuidsForIndexing(DbSession dbSession, Collection<String> uuids, Consumer<IndexedActiveRuleDto> consumer) {
     ActiveRuleMapper mapper = mapper(dbSession);
-    executeLargeInputsWithoutOutput(ids,
+    executeLargeInputsWithoutOutput(uuids,
       pageOfIds -> mapper
-        .scrollByIdsForIndexing(pageOfIds, context -> {
+        .scrollByUuidsForIndexing(pageOfIds, context -> {
           IndexedActiveRuleDto dto = context.getResultObject();
           consumer.accept(dto);
         }));
index 44eb58b943e3f7e311e2f5493e7894c64db0468b..6cc8c2efb22862a39a958f8d15684697e0e1af53 100644 (file)
@@ -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;
   }
 
index d159244eb821dd341dc29a0cc232babb58a58822..36b75922667cc68c090e90008440f68fecc17617 100644 (file)
@@ -34,11 +34,11 @@ public interface ActiveRuleMapper {
 
   void update(ActiveRuleDto dto);
 
-  void delete(int activeRuleId);
+  void delete(String activeRuleUuid);
 
   void deleteByRuleProfileUuids(@Param("rulesProfileUuids") Collection<String> rulesProfileUuids);
 
-  void deleteByIds(@Param("ids") Collection<Integer> ids);
+  void deleteByUuids(@Param("uuids") Collection<String> uuids);
 
   @CheckForNull
   ActiveRuleDto selectByKey(@Param("ruleProfileUuid") String ruleProfileUuid, @Param("repository") String repository, @Param("rule") String rule);
@@ -65,24 +65,24 @@ public interface ActiveRuleMapper {
 
   void updateParameter(ActiveRuleParamDto dto);
 
-  void deleteParameters(int activeRuleId);
+  void deleteParameters(String activeRuleUuid);
 
   void deleteParametersByRuleProfileUuids(@Param("rulesProfileUuids") Collection<String> rulesProfileUuids);
 
   void deleteParameter(String activeRuleParamUuid);
 
-  void deleteParamsByActiveRuleIds(@Param("activeRuleIds") Collection<Integer> activeRuleIds);
+  void deleteParamsByActiveRuleUuids(@Param("activeRuleUuids") Collection<String> activeRuleUuids);
 
-  List<ActiveRuleParamDto> selectParamsByActiveRuleId(int activeRuleId);
+  List<ActiveRuleParamDto> selectParamsByActiveRuleUuid(String activeRuleUuid);
 
-  List<ActiveRuleParamDto> selectParamsByActiveRuleIds(@Param("ids") List<Integer> ids);
+  List<ActiveRuleParamDto> selectParamsByActiveRuleUuids(@Param("uuids") List<String> uuids);
 
   List<KeyLongValue> countActiveRulesByQuery(@Param("organizationUuid") String organizationUuid, @Param("profileUuids") List<String> profileUuids,
     @Nullable @Param("ruleStatus") RuleStatus ruleStatus, @Param("inheritance") String inheritance);
 
   void scrollAllForIndexing(ResultHandler<IndexedActiveRuleDto> handler);
 
-  void scrollByIdsForIndexing(@Param("ids") Collection<Long> ids, ResultHandler<IndexedActiveRuleDto> handler);
+  void scrollByUuidsForIndexing(@Param("uuids") Collection<String> uuids, ResultHandler<IndexedActiveRuleDto> handler);
 
   void scrollByRuleProfileUuidForIndexing(@Param("ruleProfileUuid") String ruleProfileUuid, ResultHandler<IndexedActiveRuleDto> handler);
 }
index 64e61e9524b42331a3c40d9013d083658e8ba401..c42c89923a4d61b263a383ab759d41f03a7e31a5 100644 (file)
@@ -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;
   }
 
index 4204541971c6ddf1da55681be32487ff854df7e4..16dc196df7a173d1440174086a3611006d30d62a 100644 (file)
@@ -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() {
index b0f54e5c6c25ae1d042ef304205ba4f018bfadff..032fb2ca9c9f1cba57069081f22ce592719fc005 100644 (file)
 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() {
index 480522d37644ba275b9115014cdf9496e6ef0807..d953b8e6fc31f1678b19d90c02dd53a113fb133a 100644 (file)
@@ -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() {
index c811d7ae0b1ae4d2270ec37c74a11e7317ed1583..c1d15383be6f4f65a3e09449f7dd22403c33a0fa 100644 (file)
@@ -33,17 +33,17 @@ public class QualityProfileExportDao implements Dao {
   public List<ExportRuleDto> selectRulesByProfile(DbSession dbSession, QProfileDto profile) {
     List<ExportRuleDto> exportRules = mapper(dbSession).selectByProfileUuid(profile.getKee());
 
-    Map<Integer, ExportRuleDto> exportRulesById = exportRules.stream().collect(Collectors.toMap(ExportRuleDto::getActiveRuleId, x -> x));
-    Map<Integer, List<ExportRuleParamDto>> rulesParams = selectParamsByActiveRuleIds(dbSession, exportRulesById.keySet());
+    Map<String, ExportRuleDto> exportRulesByUuid = exportRules.stream().collect(Collectors.toMap(ExportRuleDto::getActiveRuleUuid, x -> x));
+    Map<String, List<ExportRuleParamDto>> rulesParams = selectParamsByActiveRuleUuids(dbSession, exportRulesByUuid.keySet());
 
-    rulesParams.forEach((id, rules) -> exportRulesById.get(id).setParams(rules));
+    rulesParams.forEach((uuid, rules) -> exportRulesByUuid.get(uuid).setParams(rules));
     return exportRules;
   }
 
-  private static Map<Integer, List<ExportRuleParamDto>> selectParamsByActiveRuleIds(DbSession dbSession, Collection<Integer> activeRuleIds) {
-    return executeLargeInputs(activeRuleIds, ids -> mapper(dbSession).selectParamsByActiveRuleIds(ids))
+  private static Map<String, List<ExportRuleParamDto>> selectParamsByActiveRuleUuids(DbSession dbSession, Collection<String> activeRuleUuids) {
+    return executeLargeInputs(activeRuleUuids, uuids -> mapper(dbSession).selectParamsByActiveRuleUuids(uuids))
       .stream()
-      .collect(Collectors.groupingBy(ExportRuleParamDto::getActiveRuleId));
+      .collect(Collectors.groupingBy(ExportRuleParamDto::getActiveRuleUuid));
   }
 
   private static QualityProfileExportMapper mapper(DbSession dbSession) {
index 5fa06450a3c1ee90e6d37fed619dad6ce182c2a2..2f4a48ac1c0032b9068f763bd261064821b49054 100644 (file)
@@ -26,5 +26,5 @@ import org.apache.ibatis.annotations.Param;
 public interface QualityProfileExportMapper {
   List<ExportRuleDto> selectByProfileUuid(String uuid);
 
-  List<ExportRuleParamDto> selectParamsByActiveRuleIds(@Param("activeRuleIds") Collection<Integer> activeRuleIds);
+  List<ExportRuleParamDto> selectParamsByActiveRuleUuids(@Param("activeRuleUuids") Collection<String> activeRuleUuids);
 }
index 515cbe79661905ffb50e800bde838b3c4cec9e57..7649914ce453851aa24e9182ca9d9d2acbb5e1c1 100644 (file)
@@ -4,7 +4,7 @@
 <mapper namespace="org.sonar.db.qualityprofile.ActiveRuleMapper">
 
   <sql id="activeRuleColumns">
-    a.id,
+    a.uuid,
     a.profile_id as "profileId",
     a.rule_id as "ruleId",
     a.failure_level as "severity",
@@ -17,7 +17,7 @@
   </sql>
 
   <sql id="orgActiveRuleColumns">
-    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
   </sql>
 
-  <insert id="insert" parameterType="ActiveRule" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="ActiveRule">
     insert into active_rules (
+      uuid,
       profile_id,
       rule_id,
       failure_level,
@@ -46,6 +47,7 @@
       created_at,
       updated_at
     ) values (
+      #{uuid, jdbcType=VARCHAR},
       #{profileId, jdbcType=BIGINT},
       #{ruleId, jdbcType=BIGINT},
       #{severity, jdbcType=INTEGER},
       inheritance = #{inheritance, jdbcType=VARCHAR},
       updated_at = #{updatedAt, jdbcType=BIGINT}
     where
-      id = #{id, jdbcType=BIGINT}
+      uuid = #{uuid, jdbcType=BIGINT}
   </update>
 
-  <delete id="delete" parameterType="int">
+  <delete id="delete" parameterType="String">
     delete from active_rules
     where
-      id=#{id, jdbcType=BIGINT}
+      uuid=#{uuid, jdbcType=BIGINT}
   </delete>
 
   <delete id="deleteByRuleProfileUuids" parameterType="String">
       )
   </delete>
 
-  <delete id="deleteByIds" parameterType="Integer">
+  <delete id="deleteByUuids" parameterType="String">
     delete from active_rules
     where
-      id in
-        <foreach collection="ids" open="(" close=")" item="id" separator=",">#{id, jdbcType=INTEGER}</foreach>
+      uuid in
+        <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
   </delete>
 
   <select id="selectByKey" parameterType="map" resultType="ActiveRule">
 
   <sql id="activeRuleParamColumns">
     p.uuid,
-    p.active_rule_id as activeRuleId,
+    p.active_rule_uuid as activeRuleUuid,
     p.rules_parameter_id as rulesParameterId,
     p.rules_parameter_key as kee,
     p.value as value
   <insert id="insertParameter" parameterType="ActiveRuleParam" useGeneratedKeys="false">
     insert into active_rule_parameters (
       uuid,
-      active_rule_id,
+      active_rule_uuid,
       rules_parameter_id,
       rules_parameter_key,
       value
     ) values (
       #{uuid, jdbcType=VARCHAR},
-      #{activeRuleId, jdbcType=BIGINT},
+      #{activeRuleUuid, jdbcType=VARCHAR},
       #{rulesParameterId, jdbcType=BIGINT},
       #{key, jdbcType=VARCHAR},
       #{value, jdbcType=VARCHAR}
     WHERE uuid=#{uuid, jdbcType=VARCHAR}
   </update>
 
-  <delete id="deleteParameters" parameterType="int">
-    DELETE FROM active_rule_parameters WHERE active_rule_id=#{activeRuleId, jdbcType=BIGINT}
+  <delete id="deleteParameters" parameterType="String">
+    DELETE FROM active_rule_parameters WHERE active_rule_uuid=#{activeRuleUuid, jdbcType=BIGINT}
   </delete>
 
   <delete id="deleteParametersByRuleProfileUuids" parameterType="String">
     where exists (
       select 1 from active_rules ar
       inner join rules_profiles rp on rp.id = ar.profile_id
-      where ar.id = active_rule_id
+      where ar.uuid = active_rule_uuid
       and rp.kee in
         <foreach collection="rulesProfileUuids" open="(" close=")" item="rulesProfileUuid" separator=",">
         #{rulesProfileUuid, jdbcType=VARCHAR}
     DELETE FROM active_rule_parameters WHERE uuid=#{uuid, jdbcType=VARCHAR}
   </delete>
 
-  <delete id="deleteParamsByActiveRuleIds" parameterType="Integer">
+  <delete id="deleteParamsByActiveRuleUuids" parameterType="String">
     delete from active_rule_parameters
     where
-      active_rule_id in
-    <foreach collection="activeRuleIds" open="(" close=")" item="activeRuleId" separator=",">#{activeRuleId, jdbcType=INTEGER}</foreach>
+      active_rule_uuid in
+    <foreach collection="activeRuleUuids" open="(" close=")" item="activeRuleUuid" separator=",">#{activeRuleUuid, jdbcType=VARCHAR}</foreach>
   </delete>
 
-  <select id="selectParamsByActiveRuleId" parameterType="Integer" resultType="ActiveRuleParam">
+  <select id="selectParamsByActiveRuleUuid" parameterType="String" resultType="ActiveRuleParam">
     select
     <include refid="activeRuleParamColumns"/>
     from active_rule_parameters p
     <where>
-      p.active_rule_id=#{id, jdbcType=BIGINT}
+      p.active_rule_uuid=#{uuid, jdbcType=VARCHAR}
     </where>
   </select>
 
-  <select id="selectParamsByActiveRuleIds" parameterType="map" resultType="ActiveRuleParam">
+  <select id="selectParamsByActiveRuleUuids" parameterType="map" resultType="ActiveRuleParam">
     select
     <include refid="activeRuleParamColumns"/>
     from active_rule_parameters p
     <where>
-      <foreach collection="ids" item="id" open="(" separator=" or " close=")">
-        p.active_rule_id=#{id, jdbcType=BIGINT}
+      <foreach collection="uuids" item="uuid" open="(" separator=" or " close=")">
+        p.active_rule_uuid=#{uuid, jdbcType=VARCHAR}
       </foreach>
     </where>
   </select>
 
   <select id="countActiveRulesByQuery" resultType="KeyLongValue" parameterType="map">
-    select oqp.uuid as "key", count(ar.id) as "value"
+    select oqp.uuid as "key", count(ar.uuid) as "value"
     from active_rules ar
     inner join rules_profiles rp on rp.id = ar.profile_id
     inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
     <include refid="scrollAllForIndexingSql"/>
   </select>
 
-  <select id="scrollByIdsForIndexing" parameterType="map" resultType="org.sonar.db.qualityprofile.IndexedActiveRuleDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
+  <select id="scrollByUuidsForIndexing" parameterType="map" resultType="org.sonar.db.qualityprofile.IndexedActiveRuleDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
     <include refid="scrollAllForIndexingSql"/>
-    where ar.id in
-    <foreach collection="ids" open="(" close=")" item="id" separator=",">#{id, jdbcType=BIGINT}</foreach>
+    where ar.uuid in
+    <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
   </select>
 
   <select id="scrollByRuleProfileUuidForIndexing" parameterType="String" resultType="org.sonar.db.qualityprofile.IndexedActiveRuleDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
 
   <sql id="scrollAllForIndexingSql">
     select
-    ar.id as "id",
+    ar.uuid as "uuid",
     ar.failure_level as "severity",
     ar.inheritance as "inheritance",
     r.id as "ruleId",
index ec8fe7a81e3074b99b425f62f04540f5899d7ab4..18f2256dfe6098bb75cb47629177f0304a172616 100644 (file)
@@ -4,7 +4,7 @@
 <mapper namespace="org.sonar.db.qualityprofile.QualityProfileExportMapper">
 
   <sql id="exportRuleColumns">
-    a.id as "activeRuleId",
+    a.uuid as "activeRuleUuid",
     a.failure_level as "severity",
     r.plugin_rule_key as "rule",
     r.plugin_name as "repository",
@@ -19,7 +19,7 @@
   </sql>
 
   <sql id="exportRuleParamColumns">
-    p.active_rule_id as activeRuleId,
+    p.active_rule_uuid as activeRuleUuid,
     p.rules_parameter_key as kee,
     p.value as value
   </sql>
     where oqp.uuid = #{id, jdbcType=VARCHAR}
   </select>
 
-  <select id="selectParamsByActiveRuleIds" parameterType="map" resultType="org.sonar.db.qualityprofile.ExportRuleParamDto">
+  <select id="selectParamsByActiveRuleUuids" parameterType="map" resultType="org.sonar.db.qualityprofile.ExportRuleParamDto">
     select
     <include refid="exportRuleParamColumns"/>
     from active_rule_parameters p
     <where>
-    p.active_rule_id in <foreach collection="activeRuleIds" open="(" close=")" item="activeRuleId" separator=",">#{activeRuleId,jdbcType=INTEGER}</foreach>
+    p.active_rule_uuid in <foreach collection="activeRuleUuids" open="(" close=")" item="activeRuleUuid" separator=",">#{activeRuleUuid,jdbcType=VARCHAR}</foreach>
     </where>
   </select>
 </mapper>
index 0c8f91f99b2e3eab629927bef3d6666356133c88..98df38e29737afcd528b008f9fc89a885bb0f5f0 100644 (file)
@@ -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"(
index 805cf94307f6b926342661ff60cc685b3c9b4ca3..418fc1b8efb8fa5b20046a2ddd3db0c084955357 100644 (file)
@@ -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<ActiveRuleParamDto> reloaded = underTest.selectParamsByActiveRuleId(dbSession, activeRule.getId());
+    List<ActiveRuleParamDto> reloaded = underTest.selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid());
     assertThat(reloaded).hasSize(1);
     assertThat(reloaded.get(0))
       .matches(p -> Objects.equals(p.getUuid(), activeRuleParam.getUuid()))
       .matches(p -> p.getKey().equals(activeRuleParam.getKey()))
-      .matches(p -> p.getActiveRuleId().equals(activeRule.getId()))
+      .matches(p -> p.getActiveRuleUuid().equals(activeRule.getUuid()))
       .matches(p -> p.getRulesParameterId().equals(rule1Param1.getId()))
       .matches(p -> p.getValue().equals("foo"));
   }
@@ -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<ActiveRuleParamDto> reloaded = underTest.selectParamsByActiveRuleId(dbSession, activeRule.getId());
+    List<ActiveRuleParamDto> reloaded = underTest.selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid());
     assertThat(reloaded).hasSize(1);
     assertThat(reloaded.get(0))
       .matches(p -> Objects.equals(p.getUuid(), activeRuleParam.getUuid()))
       .matches(p -> p.getKey().equals(activeRuleParam.getKey()))
-      .matches(p -> p.getActiveRuleId().equals(activeRule.getId()))
+      .matches(p -> p.getActiveRuleUuid().equals(activeRule.getUuid()))
       .matches(p -> p.getRulesParameterId().equals(rule1Param1.getId()))
       .matches(p -> p.getValue().equals("bar"));
   }
@@ -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<Integer> activeRuleIds = asList(activeRule1.getId(), activeRule2.getId());
-    assertThat(underTest.selectParamsByActiveRuleIds(dbSession, activeRuleIds)).hasSize(2);
+    List<String> activeRuleUuids = asList(activeRule1.getUuid(), activeRule2.getUuid());
+    assertThat(underTest.selectParamsByActiveRuleUuids(dbSession, activeRuleUuids)).hasSize(2);
 
     underTest.deleteParamsByRuleParamOfAllOrganizations(dbSession, rule1Param1);
 
-    assertThat(underTest.selectParamsByActiveRuleIds(dbSession, activeRuleIds)).isEmpty();
+    assertThat(underTest.selectParamsByActiveRuleUuids(dbSession, activeRuleUuids)).isEmpty();
   }
 
   @Test
@@ -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<IndexedActiveRuleDto> {
index 5e92fcc0313e9bc5052f74ee6c1ba3c4c96db495..ab01c620b85e82d478e6eb7b096b32ba8054adc5 100644 (file)
@@ -136,8 +136,8 @@ public class QualityProfileExportDaoTest {
     List<ExportRuleDto> results = underTest.selectRulesByProfile(dbSession, profile);
 
     assertThat(results)
-      .extracting("activeRuleId")
-      .containsOnly(activatedRule.getId());
+      .extracting("activeRuleUuid")
+      .containsOnly(activatedRule.getUuid());
 
     assertThat(results.get(0).getParams())
       .extracting("key")
@@ -169,32 +169,32 @@ public class QualityProfileExportDaoTest {
     List<ExportRuleDto> otherProfileResults = underTest.selectRulesByProfile(dbSession, otherProfile);
 
     assertThat(results)
-      .extracting("activeRuleId")
-      .containsOnly(firstActivatedRule.getId(), secondActivatedRule.getId());
+      .extracting("activeRuleUuid")
+      .containsOnly(firstActivatedRule.getUuid(), secondActivatedRule.getUuid());
 
     assertThat(otherProfileResults)
-      .extracting("activeRuleId")
-      .containsOnly(thirdActivatedRule.getId());
+      .extracting("activeRuleUuid")
+      .containsOnly(thirdActivatedRule.getUuid());
 
-    ExportRuleDto firstExportedRule = findExportedRuleById(firstActivatedRule.getId(), results);
+    ExportRuleDto firstExportedRule = findExportedRuleByUuid(firstActivatedRule.getUuid(), results);
     assertThat(firstExportedRule.getParams())
       .extracting("key")
       .containsOnly(ruleParamsOfFirstRule.stream().map(RuleParamDto::getName).toArray());
 
-    ExportRuleDto secondExportedRule = findExportedRuleById(secondActivatedRule.getId(), results);
+    ExportRuleDto secondExportedRule = findExportedRuleByUuid(secondActivatedRule.getUuid(), results);
     assertThat(secondExportedRule.getParams())
       .extracting("key")
       .containsOnly(ruleParamsOfSecondRule.stream().map(RuleParamDto::getName).toArray());
 
-    ExportRuleDto thirdExportedRule = findExportedRuleById(thirdActivatedRule.getId(), otherProfileResults);
+    ExportRuleDto thirdExportedRule = findExportedRuleByUuid(thirdActivatedRule.getUuid(), otherProfileResults);
     assertThat(thirdExportedRule.getParams())
       .extracting("key")
       .containsOnly(ruleParamsOfThirdRule.stream().map(RuleParamDto::getName).toArray());
   }
 
 
-  private ExportRuleDto findExportedRuleById(Integer id, List<ExportRuleDto> results) {
-    Optional<ExportRuleDto> found = results.stream().filter(exportRuleDto -> id.equals(exportRuleDto.getActiveRuleId())).findFirst();
+  private ExportRuleDto findExportedRuleByUuid(String uuid, List<ExportRuleDto> results) {
+    Optional<ExportRuleDto> found = results.stream().filter(exportRuleDto -> uuid.equals(exportRuleDto.getActiveRuleUuid())).findFirst();
     if (!found.isPresent()) {
       Assert.fail();
     }
@@ -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);
     });
 
index a251361c1197c2a7df6c88751048797af637f3a1..4e028bead2db7f6b14dc10345319a35438ae93d0 100644 (file)
@@ -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 (file)
index 0000000..7f9347d
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..e6f532b
--- /dev/null
@@ -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 (file)
index 0000000..3aaee46
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..721d830
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..72952ee
--- /dev/null
@@ -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 (file)
index 0000000..e89cf91
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..d612ae2
--- /dev/null
@@ -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 (file)
index 0000000..3c71eba
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..19ddafd
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..3138410
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..5f71e13
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..613060e
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..2dbec7b
--- /dev/null
@@ -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 (file)
index 0000000..50d2a42
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..4901ea1
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..79911e5
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..4976d78
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..10c82a5
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..76597d2
--- /dev/null
@@ -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 (file)
index 0000000..728f696
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.platform.db.migration.version.v83.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 (file)
index 0000000..ba881fb
--- /dev/null
@@ -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 (file)
index 0000000..a428387
--- /dev/null
@@ -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 (file)
index 0000000..246c0eb
--- /dev/null
@@ -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<Map<String, Object>> select = db.select("select uuid, active_rule_id, active_rule_uuid, value from active_rule_parameters");
+    assertThat(select).extracting(m -> m.get("UUID"), m -> m.get("ACTIVE_RULE_ID"), m -> m.get("ACTIVE_RULE_UUID"), m -> m.get("VALUE"))
+      .containsExactlyInAnyOrder(tuples);
+  }
+
+  private void insertActiveRule(Long id) {
+    db.executeInsert("active_rules",
+      "uuid", "uuid" + id,
+      "id", id,
+      "profile_id", id + 1,
+      "rule_id", id + 2,
+      "failure_level", id + 3);
+  }
+
+  private void insertActiveRuleParameter(Long id, Long activeRuleId) {
+    db.executeInsert("active_rule_parameters",
+      "uuid", "uuid" + id,
+      "rules_parameter_id", id,
+      "value", "value" + id,
+      "active_rule_id", activeRuleId);
+  }
+}
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 (file)
index 0000000..f8504e8
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.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);
+  }
+}
index dde090da5bcbc1ad1b000fc7717c097d4997eca7..24c48e42de0bd69faff671e8895b3b7fd97547ab 100644 (file)
@@ -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 (file)
index 0000000..04d58e9
--- /dev/null
@@ -0,0 +1,9 @@
+CREATE TABLE "ACTIVE_RULE_PARAMETERS"(
+    "ACTIVE_RULE_ID" INTEGER NOT NULL,
+    "RULES_PARAMETER_ID" INTEGER NOT NULL,
+    "VALUE" VARCHAR(4000),
+    "RULES_PARAMETER_KEY" VARCHAR(128),
+    "UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "PK_ACTIVE_RULE_PARAMETERS" PRIMARY KEY("UUID");
+CREATE INDEX "IX_ARP_ON_ACTIVE_RULE_ID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/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 (file)
index 0000000..b074136
--- /dev/null
@@ -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 (file)
index 0000000..58802cb
--- /dev/null
@@ -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 (file)
index 0000000..f7f1874
--- /dev/null
@@ -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 (file)
index 0000000..24d5888
--- /dev/null
@@ -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 (file)
index 0000000..faf2cd0
--- /dev/null
@@ -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 (file)
index 0000000..fe510a7
--- /dev/null
@@ -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 (file)
index 0000000..642bd84
--- /dev/null
@@ -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 (file)
index 0000000..0f789b8
--- /dev/null
@@ -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 (file)
index 0000000..49569a9
--- /dev/null
@@ -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 (file)
index 0000000..5d00ec8
--- /dev/null
@@ -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 (file)
index 0000000..49569a9
--- /dev/null
@@ -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");
index 2faf6a373f45d061a1f9301ed9937940c4e85a81..96f3266202a5f320131b01d72093be4e460e49ee 100644 (file)
@@ -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<String, Object> 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
index 604c459340189b8c4210a98ecec3d1ada3b8e5a6..2657619ff60a1937ff5ebf2acfc7c1e5181ab66d 100644 (file)
@@ -88,7 +88,7 @@ public class ActiveRuleIndexer implements ResilientIndexer {
   public void commitAndIndex(DbSession dbSession, Collection<ActiveRuleChange> changes) {
     List<EsQueueDto> items = changes.stream()
       .map(ActiveRuleChange::getActiveRule)
-      .map(ar -> newQueueDto(docIdOf(ar.getId()), ID_TYPE_ACTIVE_RULE_ID, String.valueOf(ar.getRuleId())))
+      .map(ar -> newQueueDto(docIdOf(ar.getUuid()), ID_TYPE_ACTIVE_RULE_ID, String.valueOf(ar.getRuleId())))
       .collect(toArrayList());
 
     dbClient.esQueueDao().insert(dbSession, items);
@@ -153,9 +153,9 @@ public class ActiveRuleIndexer implements ResilientIndexer {
     BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, listener);
     bulkIndexer.start();
     Map<String, EsQueueDto> remaining = new HashMap<>(activeRuleItems);
-    dbClient.activeRuleDao().scrollByIdsForIndexing(dbSession, toActiveRuleIds(activeRuleItems),
+    dbClient.activeRuleDao().scrollByUuidsForIndexing(dbSession, toActiveRuleUuids(activeRuleItems),
       i -> {
-        remaining.remove(docIdOf(i.getId()));
+        remaining.remove(docIdOf(i.getUuid()));
         bulkIndexer.add(newIndexRequest(i));
       });
 
@@ -166,7 +166,7 @@ public class ActiveRuleIndexer implements ResilientIndexer {
     return bulkIndexer.stop();
   }
 
-  private static Collection<Long> toActiveRuleIds(Map<String, EsQueueDto> activeRuleItems) {
+  private static Collection<String> toActiveRuleUuids(Map<String, EsQueueDto> activeRuleItems) {
     Set<String> docIds = activeRuleItems.keySet();
     return docIds.stream()
       .map(ActiveRuleDoc::activeRuleIdOf)
@@ -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()));
index 90f924bb7ef67c1022bd3567bf2b9748e06a8cef..a580c71b27d0f23be282853b8af451a53542c172 100644 (file)
@@ -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<String> docs = es.getIds(TYPE_ACTIVE_RULE);
     assertThat(docs).hasSize(expected.length);
     for (ActiveRuleDto activeRuleDto : expected) {
-      assertThat(docs).contains("ar_" + activeRuleDto.getId());
+      assertThat(docs).contains("ar_" + activeRuleDto.getUuid());
     }
   }
 
   private void verify(ActiveRuleDoc doc1, QProfileDto profile, ActiveRuleDto activeRule) {
     assertThat(doc1)
-      .matches(doc -> doc.getId().equals("ar_" + activeRule.getId()))
+      .matches(doc -> doc.getId().equals("ar_" + activeRule.getUuid()))
       .matches(doc -> doc.getRuleProfileUuid().equals(profile.getRulesProfileUuid()))
       .matches(doc -> doc.getSeverity().equals(activeRule.getSeverityString()));
   }
index f8892e06b22ddfaaff338ea31e8bab68e66a0451..8cc18f2713bbe017a7647c3ba9a7b246068b8e09 100644 (file)
@@ -102,9 +102,9 @@ class RuleActivationContext {
   }
 
   private void register(Collection<ActiveRuleDto> activeRules, Collection<ActiveRuleParamDto> activeRuleParams) {
-    ListMultimap<Integer, ActiveRuleParamDto> paramsByActiveRuleId = activeRuleParams.stream().collect(index(ActiveRuleParamDto::getActiveRuleId));
+    ListMultimap<String, ActiveRuleParamDto> paramsByActiveRuleId = activeRuleParams.stream().collect(index(ActiveRuleParamDto::getActiveRuleUuid));
     for (ActiveRuleDto activeRule : activeRules) {
-      ActiveRuleWrapper wrapper = new ActiveRuleWrapper(activeRule, paramsByActiveRuleId.get(activeRule.getId()));
+      ActiveRuleWrapper wrapper = new ActiveRuleWrapper(activeRule, paramsByActiveRuleId.get(activeRule.getUuid()));
       this.activeRulesByKey.put(activeRule.getKey(), wrapper);
     }
   }
index 1c98b813267e694c700ce3a3326be2fe1f5792a7..1d8b6ab81967285031c316693dc4116e07f100e5 100644 (file)
@@ -408,8 +408,8 @@ public class RuleActivator {
         .map(QProfileDto::getRulesProfileUuid)
         .collect(MoreCollectors.toHashSet());
       Collection<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRulesAndRuleProfileUuids(dbSession, ruleIds, ruleProfileUuids);
-      List<Integer> activeRuleIds = activeRules.stream().map(ActiveRuleDto::getId).collect(MoreCollectors.toArrayList(activeRules.size()));
-      List<ActiveRuleParamDto> activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds);
+      List<String> activeRuleUuids = activeRules.stream().map(ActiveRuleDto::getUuid).collect(MoreCollectors.toArrayList(activeRules.size()));
+      List<ActiveRuleParamDto> activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids);
       return new DescendantProfilesSupplier.Result(profiles, activeRules, activeRuleParams);
     };
   }
@@ -423,8 +423,8 @@ public class RuleActivator {
   private void completeWithActiveRules(DbSession dbSession, RuleActivationContext.Builder builder, Collection<Integer> ruleIds, Collection<String> ruleProfileUuids) {
     Collection<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRulesAndRuleProfileUuids(dbSession, ruleIds, ruleProfileUuids);
     builder.setActiveRules(activeRules);
-    List<Integer> activeRuleIds = activeRules.stream().map(ActiveRuleDto::getId).collect(MoreCollectors.toArrayList(activeRules.size()));
-    builder.setActiveRuleParams(db.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds));
+    List<String> activeRuleUuids = activeRules.stream().map(ActiveRuleDto::getUuid).collect(MoreCollectors.toArrayList(activeRules.size()));
+    builder.setActiveRuleParams(db.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids));
   }
 
   private static boolean isSame(ActiveRuleChange change, ActiveRuleWrapper activeRule) {
index d90f8c8078c008d2799b32cdc213add7509928d8..e88ed59fc79ba3d7a67af4afa4674d6a73dc1076 100644 (file)
@@ -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<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRule.getId());
+    List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid());
     assertThat(params).isEmpty();
 
     QProfileChangeQuery changeQuery = new QProfileChangeQuery(profile.getKee());
index 76496951834d1fd2457a73cb3bdf39d106c38745..ec503feab87a1d5d632b0fbe7f0043c25e1d1a69 100644 (file)
@@ -357,12 +357,12 @@ public class BuiltInQProfileUpdateImplTest {
     assertThat(activeRule.getCreatedAt()).isNotNull();
     assertThat(activeRule.getUpdatedAt()).isNotNull();
 
-    List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId());
+    List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
     assertThat(params).hasSize(expectedParams.size());
 
     if (changes != null) {
       ActiveRuleChange change = changes.stream()
-        .filter(c -> c.getActiveRule().getId().equals(activeRule.getId()))
+        .filter(c -> c.getActiveRule().getUuid().equals(activeRule.getUuid()))
         .findFirst().orElseThrow(IllegalStateException::new);
       assertThat(change.getInheritance()).isEqualTo(expectedInheritance);
       assertThat(change.getSeverity()).isEqualTo(expectedSeverity);
@@ -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);
   }
index b27fc4e20e0f190ba9284998de7119f75476c3c7..8a3cbadc612e2687930910c881fe3d1370b1da6f 100644 (file)
@@ -70,8 +70,8 @@ public class QProfileComparison {
 
   private void compareActivationParams(DbSession session, ActiveRuleDto leftRule, ActiveRuleDto rightRule, QProfileComparisonResult result) {
     RuleKey key = leftRule.getRuleKey();
-    Map<String, String> leftParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleId(session, leftRule.getId()));
-    Map<String, String> rightParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleId(session, rightRule.getId()));
+    Map<String, String> leftParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleUuid(session, leftRule.getUuid()));
+    Map<String, String> rightParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleUuid(session, rightRule.getUuid()));
     if (leftParams.equals(rightParams) && leftRule.getSeverityString().equals(rightRule.getSeverityString())) {
       result.same.put(key, leftRule);
     } else {
index 3ac3b4c3d2d88e1a136d637368400b41d175e39f..54432c9af0ba989e9c0d6b7030c0f1c7ba6f1147 100644 (file)
@@ -119,14 +119,14 @@ public class QProfileExporters {
   private RulesProfile wrap(DbSession dbSession, QProfileDto profile) {
     RulesProfile target = new RulesProfile(profile.getName(), profile.getLanguage());
     List<OrgActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByProfile(dbSession, profile);
-    List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, Lists.transform(activeRuleDtos, ActiveRuleDto::getId));
-    ListMultimap<Integer, ActiveRuleParamDto> activeRuleParamsByActiveRuleId = FluentIterable.from(activeRuleParamDtos).index(ActiveRuleParamDto::getActiveRuleId);
+    List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, Lists.transform(activeRuleDtos, ActiveRuleDto::getUuid));
+    ListMultimap<String, ActiveRuleParamDto> activeRuleParamsByActiveRuleUuid = FluentIterable.from(activeRuleParamDtos).index(ActiveRuleParamDto::getActiveRuleUuid);
 
     for (ActiveRuleDto activeRule : activeRuleDtos) {
       // TODO all rules should be loaded by using one query with all active rule keys as parameter
       Rule rule = ruleFinder.findByKey(activeRule.getRuleKey());
       org.sonar.api.rules.ActiveRule wrappedActiveRule = target.activateRule(rule, RulePriority.valueOf(activeRule.getSeverityString()));
-      List<ActiveRuleParamDto> paramDtos = activeRuleParamsByActiveRuleId.get(activeRule.getId());
+      List<ActiveRuleParamDto> paramDtos = activeRuleParamsByActiveRuleUuid.get(activeRule.getUuid());
       for (ActiveRuleParamDto activeRuleParamDto : paramDtos) {
         wrappedActiveRule.setParameter(activeRuleParamDto.getKey(), activeRuleParamDto.getValue());
       }
index 388c1ecf44c40dea085a0c9971249af243331749..9978e30fdf9bca2f058c9e46bdb87d36304ac927 100644 (file)
@@ -98,14 +98,14 @@ public class QProfileRulesImpl implements QProfileRules {
   @Override
   public List<ActiveRuleChange> deleteRule(DbSession dbSession, RuleDefinitionDto rule) {
     List<ActiveRuleChange> changes = new ArrayList<>();
-    List<Integer> activeRuleIds = new ArrayList<>();
+    List<String> activeRuleUuids = new ArrayList<>();
     db.activeRuleDao().selectByRuleIdOfAllOrganizations(dbSession, rule.getId()).forEach(ar -> {
-      activeRuleIds.add(ar.getId());
+      activeRuleUuids.add(ar.getUuid());
       changes.add(new ActiveRuleChange(ActiveRuleChange.Type.DEACTIVATED, ar, rule));
     });
 
-    db.activeRuleDao().deleteByIds(dbSession, activeRuleIds);
-    db.activeRuleDao().deleteParamsByActiveRuleIds(dbSession, activeRuleIds);
+    db.activeRuleDao().deleteByUuids(dbSession, activeRuleUuids);
+    db.activeRuleDao().deleteParamsByActiveRuleUuids(dbSession, activeRuleUuids);
 
     return changes;
   }
index 4f669fc61982951ebae5032a2e7f01d9bdf0b9c4..73b40ae3c4fd7c0dff2439c85365620c98d2c3d9 100644 (file)
@@ -230,11 +230,11 @@ public class RuleUpdater {
 
   private Multimap<ActiveRuleDto, ActiveRuleParamDto> getActiveRuleParamsByActiveRule(DbSession dbSession, OrganizationDto organization, RuleDto customRule) {
     List<OrgActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRuleId(dbSession, organization, customRule.getId());
-    Map<Integer, OrgActiveRuleDto> activeRuleById = from(activeRuleDtos).uniqueIndex(ActiveRuleDto::getId);
-    List<Integer> activeRuleIds = Lists.transform(activeRuleDtos, ActiveRuleDto::getId);
-    List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds);
+    Map<String, OrgActiveRuleDto> activeRuleByUuid = from(activeRuleDtos).uniqueIndex(ActiveRuleDto::getUuid);
+    List<String> activeRuleUuids = Lists.transform(activeRuleDtos, ActiveRuleDto::getUuid);
+    List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids);
     return from(activeRuleParamDtos)
-      .index(new ActiveRuleParamToActiveRule(activeRuleById));
+      .index(new ActiveRuleParamToActiveRule(activeRuleByUuid));
   }
 
   private void deleteOrUpdateParameters(DbSession dbSession, RuleUpdate update, RuleDto customRule, List<String> paramKeys,
@@ -269,15 +269,15 @@ public class RuleUpdater {
   }
 
   private static class ActiveRuleParamToActiveRule implements Function<ActiveRuleParamDto, ActiveRuleDto> {
-    private final Map<Integer, OrgActiveRuleDto> activeRuleById;
+    private final Map<String, OrgActiveRuleDto> activeRuleByUuid;
 
-    private ActiveRuleParamToActiveRule(Map<Integer, OrgActiveRuleDto> activeRuleById) {
-      this.activeRuleById = activeRuleById;
+    private ActiveRuleParamToActiveRule(Map<String, OrgActiveRuleDto> activeRuleByUuid) {
+      this.activeRuleByUuid = activeRuleByUuid;
     }
 
     @Override
     public OrgActiveRuleDto apply(@Nonnull ActiveRuleParamDto input) {
-      return activeRuleById.get(input.getActiveRuleId());
+      return activeRuleByUuid.get(input.getActiveRuleUuid());
     }
   }
 
@@ -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());
       }
     }
   }
index 76c731213d8a56f6fa13a0b97dd59e52d67b8299..3a17472127ba22d5b7a19cbd3f234fb449614be5 100644 (file)
@@ -126,14 +126,14 @@ public class ActiveRuleCompleter {
   }
 
   private ListMultimap<ActiveRuleKey, ActiveRuleParamDto> loadParams(DbSession dbSession, List<OrgActiveRuleDto> activeRules) {
-    Map<Integer, ActiveRuleKey> activeRuleIdsByKey = new HashMap<>();
+    Map<String, ActiveRuleKey> activeRuleUuidsByKey = new HashMap<>();
     for (OrgActiveRuleDto activeRule : activeRules) {
-      activeRuleIdsByKey.put(activeRule.getId(), activeRule.getKey());
+      activeRuleUuidsByKey.put(activeRule.getUuid(), activeRule.getKey());
     }
-    List<ActiveRuleParamDto> activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, Lists.transform(activeRules, ActiveRuleDto::getId));
+    List<ActiveRuleParamDto> activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, Lists.transform(activeRules, ActiveRuleDto::getUuid));
     ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = ArrayListMultimap.create(activeRules.size(), 10);
     for (ActiveRuleParamDto activeRuleParam : activeRuleParams) {
-      ActiveRuleKey activeRuleKey = activeRuleIdsByKey.get(activeRuleParam.getActiveRuleId());
+      ActiveRuleKey activeRuleKey = activeRuleUuidsByKey.get(activeRuleParam.getActiveRuleUuid());
       activeRuleParamsByActiveRuleKey.put(activeRuleKey, activeRuleParam);
     }
 
@@ -142,16 +142,16 @@ public class ActiveRuleCompleter {
 
   List<Rules.Active> completeShow(DbSession dbSession, OrganizationDto organization, RuleDefinitionDto rule) {
     List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByRuleId(dbSession, organization, rule.getId());
-    Map<Integer, ActiveRuleKey> activeRuleIdsByKey = new HashMap<>();
+    Map<String, ActiveRuleKey> activeRuleUuidsByKey = new HashMap<>();
     for (OrgActiveRuleDto activeRuleDto : activeRules) {
-      activeRuleIdsByKey.put(activeRuleDto.getId(), activeRuleDto.getKey());
+      activeRuleUuidsByKey.put(activeRuleDto.getUuid(), activeRuleDto.getKey());
     }
 
-    List<Integer> activeRuleIds = activeRules.stream().map(ActiveRuleDto::getId).collect(Collectors.toList());
-    List<ActiveRuleParamDto> activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds);
+    List<String> activeRuleUuids = activeRules.stream().map(ActiveRuleDto::getUuid).collect(Collectors.toList());
+    List<ActiveRuleParamDto> activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids);
     ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = ArrayListMultimap.create(activeRules.size(), 10);
     for (ActiveRuleParamDto activeRuleParamDto : activeRuleParams) {
-      ActiveRuleKey activeRuleKey = activeRuleIdsByKey.get(activeRuleParamDto.getActiveRuleId());
+      ActiveRuleKey activeRuleKey = activeRuleUuidsByKey.get(activeRuleParamDto.getActiveRuleUuid());
       activeRuleParamsByActiveRuleKey.put(activeRuleKey, activeRuleParamDto);
     }
 
index 4249607a617bf9dfe5d585347ed26287e352f6ed..c0116aa02a272609435009a767594d9101c7c079 100644 (file)
@@ -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;
   }
index 24744f0b07b10b620996bd0b26745db3ba361514..5f58d10367cc80f41a1356cbce8246150e5e8c9b 100644 (file)
@@ -908,12 +908,12 @@ public class QProfileRuleImplTest {
     assertThat(activeRule.getCreatedAt()).isNotNull();
     assertThat(activeRule.getUpdatedAt()).isNotNull();
 
-    List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId());
+    List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
     assertThat(params).hasSize(expectedParams.size());
 
     if (changes != null) {
       ActiveRuleChange change = changes.stream()
-        .filter(c -> c.getActiveRule().getId().equals(activeRule.getId()))
+        .filter(c -> c.getActiveRule().getUuid().equals(activeRule.getUuid()))
         .findFirst().orElseThrow(IllegalStateException::new);
       assertThat(change.getInheritance()).isEqualTo(expectedInheritance);
       assertThat(change.getSeverity()).isEqualTo(expectedSeverity);
@@ -943,7 +943,7 @@ public class QProfileRuleImplTest {
     assertThat(activeRule.getCreatedAt()).isNotNull();
     assertThat(activeRule.getUpdatedAt()).isNotNull();
 
-    List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId());
+    List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
     assertThat(params).hasSize(expectedParams.size());
   }
 
index 91bab9c841c167ca8fdc3d8de4c015e0da51b29a..4add5ec8ab80c04a73497588f131dac144d1d717 100644 (file)
@@ -221,12 +221,12 @@ public class QProfileTreeImplTest {
     assertThat(activeRule.getCreatedAt()).isNotNull();
     assertThat(activeRule.getUpdatedAt()).isNotNull();
 
-    List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId());
+    List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
     assertThat(params).hasSize(expectedParams.size());
 
     if (changes != null) {
       ActiveRuleChange change = changes.stream()
-        .filter(c -> c.getActiveRule().getId().equals(activeRule.getId()))
+        .filter(c -> c.getActiveRule().getUuid().equals(activeRule.getUuid()))
         .findFirst().orElseThrow(IllegalStateException::new);
       assertThat(change.getInheritance()).isEqualTo(expectedInheritance);
       assertThat(change.getSeverity()).isEqualTo(expectedSeverity);
@@ -256,7 +256,7 @@ public class QProfileTreeImplTest {
     assertThat(activeRule.getCreatedAt()).isNotNull();
     assertThat(activeRule.getUpdatedAt()).isNotNull();
 
-    List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId());
+    List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
     assertThat(params).hasSize(expectedParams.size());
   }
 
index 369908c5e45c883008ca6b05cc708e6ebe80e9a9..4832470ba06d33388c7bcdf151c327f208477213 100644 (file)
@@ -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<ActiveRuleParamDto> activeRuleParams = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleReloaded.getId());
+    List<ActiveRuleParamDto> activeRuleParams = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(dbSession, activeRuleReloaded.getUuid());
 
     assertThat(activeRuleParams).hasSize(2);
     Map<String, ActiveRuleParamDto> activeRuleParamsByKey = ActiveRuleParamDto.groupByKey(activeRuleParams);