Quellcode durchsuchen

SONAR-13221 change PK to uuid of RULES_PROFILES table

* change profile_id to profile_uuid for ACTIVE_RULES
tags/8.4.0.35506
Jacek vor 4 Jahren
Ursprung
Commit
94711e1ee7
79 geänderte Dateien mit 2248 neuen und 189 gelöschten Zeilen
  1. 3
    3
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java
  2. 7
    7
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java
  3. 1
    1
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleKey.java
  4. 5
    5
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/OrgActiveRuleDto.java
  5. 1
    12
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java
  6. 1
    4
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java
  7. 7
    22
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java
  8. 29
    29
      server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml
  9. 2
    2
      server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileChangeMapper.xml
  10. 2
    2
      server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml
  11. 28
    30
      server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
  12. 6
    8
      server/sonar-db-dao/src/schema/schema-sq.ddl
  13. 10
    10
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java
  14. 10
    12
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
  15. 1
    1
      server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileTesting.java
  16. 44
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
  17. 38
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTable.java
  18. 31
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTable.java
  19. 33
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTable.java
  20. 41
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTable.java
  21. 32
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTable.java
  22. 52
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTable.java
  23. 32
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullable.java
  24. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuid.java
  25. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTable.java
  26. 67
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable.java
  27. 41
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTable.java
  28. 52
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTable.java
  29. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullable.java
  30. 49
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuid.java
  31. 48
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuid.java
  32. 48
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuid.java
  33. 49
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest.java
  34. 67
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTableTest.java
  35. 49
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTableTest.java
  36. 49
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTableTest.java
  37. 54
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.java
  38. 54
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest.java
  39. 43
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullableTest.java
  40. 81
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuidTest.java
  41. 63
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTableTest.java
  42. 51
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest.java
  43. 49
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTableTest.java
  44. 51
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest.java
  45. 43
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullableTest.java
  46. 113
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuidTest.java
  47. 137
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuidTest.java
  48. 136
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuidTest.java
  49. 10
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest/schema.sql
  50. 12
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTableTest/schema.sql
  51. 11
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTableTest/schema.sql
  52. 13
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTableTest/schema.sql
  53. 11
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest/schema.sql
  54. 13
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest/schema.sql
  55. 13
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullableTest/schema.sql
  56. 13
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuidTest/schema.sql
  57. 11
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTableTest/schema.sql
  58. 11
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest/schema.sql
  59. 12
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTableTest/schema.sql
  60. 12
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest/schema.sql
  61. 26
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullableTest/schema.sql
  62. 26
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuidTest/schema.sql
  63. 28
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuidTest/schema.sql
  64. 24
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuidTest/schema.sql
  65. 1
    1
      server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java
  66. 3
    3
      server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java
  67. 3
    3
      server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java
  68. 3
    3
      server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
  69. 1
    1
      server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java
  70. 2
    3
      server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java
  71. 4
    4
      server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java
  72. 1
    1
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java
  73. 1
    1
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java
  74. 2
    2
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
  75. 16
    14
      server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java
  76. 1
    1
      server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java
  77. 1
    1
      server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java
  78. 2
    2
      server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java
  79. 1
    1
      server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java

+ 3
- 3
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java Datei anzeigen

@@ -86,7 +86,7 @@ public class ActiveRuleDao implements Dao {
}

public List<ActiveRuleDto> selectByRuleProfile(DbSession dbSession, RulesProfileDto ruleProfileDto) {
return mapper(dbSession).selectByRuleProfileUuid(ruleProfileDto.getKee());
return mapper(dbSession).selectByRuleProfileUuid(ruleProfileDto.getUuid());
}

public Collection<ActiveRuleDto> selectByRulesAndRuleProfileUuids(DbSession dbSession, Collection<Integer> ruleIds, Collection<String> ruleProfileUuids) {
@@ -98,7 +98,7 @@ public class ActiveRuleDao implements Dao {
}

public ActiveRuleDto insert(DbSession dbSession, ActiveRuleDto item) {
checkArgument(item.getProfileId() != null, QUALITY_PROFILE_IS_NOT_PERSISTED);
checkArgument(item.getProfileUuid() != null, QUALITY_PROFILE_IS_NOT_PERSISTED);
checkArgument(item.getRuleId() != null, RULE_IS_NOT_PERSISTED);
checkArgument(item.getUuid() == null, ACTIVE_RULE_IS_ALREADY_PERSISTED);

@@ -108,7 +108,7 @@ public class ActiveRuleDao implements Dao {
}

public ActiveRuleDto update(DbSession dbSession, ActiveRuleDto item) {
checkArgument(item.getProfileId() != null, QUALITY_PROFILE_IS_NOT_PERSISTED);
checkArgument(item.getProfileUuid() != null, QUALITY_PROFILE_IS_NOT_PERSISTED);
checkArgument(item.getRuleId() != null, ActiveRuleDao.RULE_IS_NOT_PERSISTED);
checkArgument(item.getUuid() != null, ACTIVE_RULE_IS_NOT_PERSISTED);
mapper(dbSession).update(item);

+ 7
- 7
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java Datei anzeigen

@@ -37,7 +37,7 @@ public class ActiveRuleDto {
public static final String OVERRIDES = ActiveRule.OVERRIDES;

private String uuid;
private Integer profileId;
private String profileUuid;
private Integer ruleId;
private Integer severity;
private String inheritance;
@@ -75,12 +75,12 @@ public class ActiveRuleDto {
return this;
}

public Integer getProfileId() {
return profileId;
public String getProfileUuid() {
return profileUuid;
}

public ActiveRuleDto setProfileId(Integer profileId) {
this.profileId = profileId;
public ActiveRuleDto setProfileUuid(String profileUuid) {
this.profileUuid = profileUuid;
return this;
}

@@ -157,10 +157,10 @@ public class ActiveRuleDto {
}

public static ActiveRuleDto createFor(QProfileDto profile, RuleDefinitionDto ruleDto) {
requireNonNull(profile.getId(), "Profile is not persisted");
requireNonNull(profile.getRulesProfileUuid(), "Profile is not persisted");
requireNonNull(ruleDto.getId(), "Rule is not persisted");
ActiveRuleDto dto = new ActiveRuleDto();
dto.setProfileId(profile.getId());
dto.setProfileUuid(profile.getRulesProfileUuid());
dto.setRuleId(ruleDto.getId());
dto.setKey(ActiveRuleKey.of(profile, ruleDto.getKey()));
return dto;

+ 1
- 1
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleKey.java Datei anzeigen

@@ -45,7 +45,7 @@ public class ActiveRuleKey implements Serializable, Comparable<ActiveRuleKey> {
}

public static ActiveRuleKey of(RulesProfileDto rulesProfile, RuleKey ruleKey) {
return new ActiveRuleKey(rulesProfile.getKee(), ruleKey);
return new ActiveRuleKey(rulesProfile.getUuid(), ruleKey);
}

/**

+ 5
- 5
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/OrgActiveRuleDto.java Datei anzeigen

@@ -22,7 +22,7 @@ package org.sonar.db.qualityprofile;
public class OrgActiveRuleDto extends ActiveRuleDto {

private String organizationUuid;
private String profileUuid;
private String orgProfileUuid;

public String getOrganizationUuid() {
return organizationUuid;
@@ -33,12 +33,12 @@ public class OrgActiveRuleDto extends ActiveRuleDto {
return this;
}

public String getProfileUuid() {
return profileUuid;
public String getOrgProfileUuid() {
return orgProfileUuid;
}

public OrgActiveRuleDto setProfileUuid(String s) {
this.profileUuid = s;
public OrgActiveRuleDto setOrgProfileUuid(String s) {
this.orgProfileUuid = s;
return this;
}
}

+ 1
- 12
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java Datei anzeigen

@@ -30,7 +30,6 @@ import org.sonar.db.organization.OrganizationDto;
*/
public class QProfileDto {

private Integer id;
/**
* The organization, that this quality profile belongs to.
* Must not be null, but can be the default organization's uuid.
@@ -74,15 +73,6 @@ public class QProfileDto {
return this;
}

public Integer getId() {
return id;
}

public QProfileDto setId(Integer id) {
this.id = id;
return this;
}

public String getName() {
return name;
}
@@ -160,8 +150,7 @@ public class QProfileDto {
.setKee(org.getUuid())
.setParentKee(org.getParentUuid())
.setOrganizationUuid(org.getOrganizationUuid())
.setId(rules.getId())
.setRulesProfileUuid(rules.getKee())
.setRulesProfileUuid(rules.getUuid())
.setLanguage(rules.getLanguage())
.setName(rules.getName())
.setRulesUpdatedAt(rules.getRulesUpdatedAt())

+ 1
- 4
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java Datei anzeigen

@@ -39,7 +39,6 @@ import org.sonar.db.RowNotFoundException;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.project.ProjectDto;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Collections.emptyList;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
import static org.sonar.db.DatabaseUtils.executeLargeUpdates;
@@ -107,12 +106,10 @@ public class QualityProfileDao implements Dao {
}

private void doInsert(QualityProfileMapper mapper, QProfileDto profile) {
checkArgument(profile.getId() == null, "Quality profile is already persisted (got id %d)", profile.getId());
long now = system.now();
RulesProfileDto rulesProfile = RulesProfileDto.from(profile);
mapper.insertRuleProfile(rulesProfile, new Date(now));
mapper.insertOrgQProfile(OrgQProfileDto.from(profile), now);
profile.setId(rulesProfile.getId());
}

public void update(DbSession dbSession, QProfileDto profile, QProfileDto... otherProfiles) {
@@ -264,7 +261,7 @@ public class QualityProfileDao implements Dao {
}

public List<QProfileDto> selectQProfilesByRuleProfile(DbSession dbSession, RulesProfileDto rulesProfile) {
return mapper(dbSession).selectQProfilesByRuleProfileUuid(rulesProfile.getKee());
return mapper(dbSession).selectQProfilesByRuleProfileUuid(rulesProfile.getUuid());
}

private static String sqlQueryString(@Nullable String query) {

+ 7
- 22
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java Datei anzeigen

@@ -35,14 +35,9 @@ import org.sonar.core.util.UtcDateUtils;
public class RulesProfileDto {

/**
* Legacy db-generated ID. Usages should be replaced by {@link #kee}.
* UUID
*/
private Integer id;

/**
* UUID. Can be a unique slug on legacy rows, for example "abap-sonar-way-38370".
*/
private String kee;
private String uuid;

/**
* Name displayed to users, for example "Sonar way". Not null.
@@ -67,21 +62,12 @@ public class RulesProfileDto {
*/
private boolean isBuiltIn;

public String getKee() {
return kee;
}

public RulesProfileDto setKee(String s) {
this.kee = s;
return this;
}

public Integer getId() {
return id;
public String getUuid() {
return uuid;
}

public RulesProfileDto setId(Integer id) {
this.id = id;
public RulesProfileDto setUuid(String s) {
this.uuid = s;
return this;
}

@@ -128,11 +114,10 @@ public class RulesProfileDto {

public static RulesProfileDto from(QProfileDto qProfileDto) {
return new RulesProfileDto()
.setKee(qProfileDto.getRulesProfileUuid())
.setUuid(qProfileDto.getRulesProfileUuid())
.setLanguage(qProfileDto.getLanguage())
.setName(qProfileDto.getName())
.setIsBuiltIn(qProfileDto.isBuiltIn())
.setId(qProfileDto.getId())
.setRulesUpdatedAt(qProfileDto.getRulesUpdatedAt());
}
}

+ 29
- 29
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml Datei anzeigen

@@ -5,42 +5,42 @@

<sql id="activeRuleColumns">
a.uuid,
a.profile_id as "profileId",
a.profile_uuid as "profileUuid",
a.rule_id as "ruleId",
a.failure_level as "severity",
a.inheritance as "inheritance",
r.plugin_rule_key as "rulefield",
r.plugin_name as "repository",
rp.kee as "ruleProfileUuid",
rp.uuid as "ruleProfileUuid",
a.created_at as "createdAt",
a.updated_at as "updatedAt"
</sql>

<sql id="orgActiveRuleColumns">
a.uuid,
a.profile_id as "profileId",
a.profile_uuid as "profileUuid",
a.rule_id as "ruleId",
a.failure_level as "severity",
a.inheritance as "inheritance",
r.plugin_rule_key as "rulefield",
r.plugin_name as "repository",
r.security_standards as "securityStandards",
rp.kee as "ruleProfileUuid",
rp.uuid as "ruleProfileUuid",
a.created_at as "createdAt",
a.updated_at as "updatedAt",
oqp.organization_uuid as "organizationUuid",
oqp.uuid as "profileUuid"
oqp.uuid as "orgProfileUuid"
</sql>

<sql id="activeRuleKeyJoin">
inner join rules_profiles rp on rp.id = a.profile_id
inner join rules_profiles rp on rp.uuid = a.profile_uuid
inner join rules r on r.id = a.rule_id
</sql>

<insert id="insert" parameterType="ActiveRule">
insert into active_rules (
uuid,
profile_id,
profile_uuid,
rule_id,
failure_level,
inheritance,
@@ -48,7 +48,7 @@
updated_at
) values (
#{uuid, jdbcType=VARCHAR},
#{profileId, jdbcType=BIGINT},
#{profileUuid, jdbcType=BIGINT},
#{ruleId, jdbcType=BIGINT},
#{severity, jdbcType=INTEGER},
#{inheritance, jdbcType=VARCHAR},
@@ -78,8 +78,8 @@
where exists (
select 1
from rules_profiles rp
where rp.id = profile_id
and rp.kee in
where rp.uuid = profile_uuid
and rp.uuid in
<foreach collection="rulesProfileUuids" open="(" close=")" item="rulesProfileUuid" separator=",">#{rulesProfileUuid, jdbcType=VARCHAR}</foreach>
)
</delete>
@@ -97,7 +97,7 @@
from active_rules a
<include refid="activeRuleKeyJoin"/>
where
rp.kee = #{ruleProfileUuid, jdbcType=VARCHAR}
rp.uuid = #{ruleProfileUuid, jdbcType=VARCHAR}
and r.plugin_rule_key = #{rule, jdbcType=VARCHAR}
and r.plugin_name = #{repository, jdbcType=VARCHAR}
</select>
@@ -109,7 +109,7 @@
<include refid="activeRuleKeyJoin"/>
where
<foreach collection="keys" item="key" open="(" separator=" or " close=")">
(rp.kee = #{key.ruleProfileUuid, jdbcType=VARCHAR}
(rp.uuid = #{key.ruleProfileUuid, jdbcType=VARCHAR}
AND r.plugin_rule_key = #{key.ruleKey.rule, jdbcType=VARCHAR}
AND r.plugin_name = #{key.ruleKey.repository, jdbcType=VARCHAR}
)
@@ -120,8 +120,8 @@
select
<include refid="orgActiveRuleColumns"/>
from active_rules a
inner join rules_profiles rp on rp.id = a.profile_id
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on rp.uuid = a.profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.uuid
inner join rules r on r.id = a.rule_id and r.status != 'REMOVED'
where oqp.uuid = #{id, jdbcType=VARCHAR}
</select>
@@ -130,8 +130,8 @@
select
<include refid="orgActiveRuleColumns"/>
from active_rules a
inner join rules_profiles rp on rp.id = a.profile_id
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on rp.uuid = a.profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.uuid
inner join rules r on r.id = a.rule_id and r.status != 'REMOVED'
where
r.rule_type in <foreach collection="types" item="type" separator="," open="(" close=")">#{type, jdbcType=INTEGER}</foreach>
@@ -144,7 +144,7 @@
from active_rules a
<include refid="activeRuleKeyJoin"/>
where
rp.kee = #{ruleProfileUuid, jdbcType=VARCHAR}
rp.uuid = #{ruleProfileUuid, jdbcType=VARCHAR}
</select>

<select id="selectByRuleIdsAndRuleProfileUuids" parameterType="map" resultType="org.sonar.db.qualityprofile.ActiveRuleDto">
@@ -154,15 +154,15 @@
<include refid="activeRuleKeyJoin"/>
where
r.id in <foreach collection="ruleIds" item="ruleId" separator="," open="(" close=")">#{ruleId, jdbcType=BIGINT}</foreach>
and rp.kee in <foreach collection="ruleProfileUuids" item="ruleProfileUuid" separator="," open="(" close=")">#{ruleProfileUuid, jdbcType=VARCHAR}</foreach>
and rp.uuid in <foreach collection="ruleProfileUuids" item="ruleProfileUuid" separator="," open="(" close=")">#{ruleProfileUuid, jdbcType=VARCHAR}</foreach>
</select>

<select id="selectByRuleId" parameterType="map" resultType="org.sonar.db.qualityprofile.OrgActiveRuleDto">
select
<include refid="orgActiveRuleColumns"/>
from active_rules a
inner join rules_profiles rp on rp.id = a.profile_id
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on rp.uuid = a.profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.uuid
inner join rules r on r.id = a.rule_id
where
a.rule_id = #{ruleId, jdbcType=BIGINT}
@@ -182,8 +182,8 @@
select
<include refid="orgActiveRuleColumns"/>
from active_rules a
inner join rules_profiles rp on rp.id = a.profile_id
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on rp.uuid = a.profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.uuid
inner join rules r on r.id = a.rule_id
where
a.rule_id in
@@ -233,9 +233,9 @@
delete from active_rule_parameters
where exists (
select 1 from active_rules ar
inner join rules_profiles rp on rp.id = ar.profile_id
inner join rules_profiles rp on rp.uuid = ar.profile_uuid
where ar.uuid = active_rule_uuid
and rp.kee in
and rp.uuid in
<foreach collection="rulesProfileUuids" open="(" close=")" item="rulesProfileUuid" separator=",">
#{rulesProfileUuid, jdbcType=VARCHAR}
</foreach>
@@ -276,8 +276,8 @@
<select id="countActiveRulesByQuery" resultType="KeyLongValue" parameterType="map">
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
inner join rules_profiles rp on rp.uuid = ar.profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.uuid
inner join rules r on r.id = ar.rule_id
<where>
oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
@@ -311,7 +311,7 @@

<select id="scrollByRuleProfileUuidForIndexing" parameterType="String" resultType="org.sonar.db.qualityprofile.IndexedActiveRuleDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
<include refid="scrollAllForIndexingSql"/>
where rp.kee = #{ruleProfileUuid, jdbcType=VARCHAR}
where rp.uuid = #{ruleProfileUuid, jdbcType=VARCHAR}
</select>

<sql id="scrollAllForIndexingSql">
@@ -322,9 +322,9 @@
r.id as "ruleId",
r.plugin_name as "repository",
r.plugin_rule_key as "key",
rp.kee as "ruleProfileUuid"
rp.uuid as "ruleProfileUuid"
from active_rules ar
inner join rules_profiles rp on rp.id = ar.profile_id
inner join rules_profiles rp on rp.uuid = ar.profile_uuid
inner join rules r on r.id = ar.rule_id
</sql>
</mapper>

+ 2
- 2
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileChangeMapper.xml Datei anzeigen

@@ -66,8 +66,8 @@

<sql id="sqlSelectByQuery">
from qprofile_changes qpc
inner join rules_profiles rp on rp.kee = qpc.rules_profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on rp.uuid = qpc.rules_profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.uuid
where
oqp.uuid = #{query.profileUuid, jdbcType=VARCHAR}
<if test="query.fromIncluded != null">

+ 2
- 2
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml Datei anzeigen

@@ -28,8 +28,8 @@
select
<include refid="exportRuleColumns"/>
from active_rules a
inner join rules_profiles rp on rp.id = a.profile_id
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on rp.uuid = a.profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.uuid
inner join rules r on r.id = a.rule_id and r.status != 'REMOVED'
left join rules rt on rt.id = r.template_id
left join rules_metadata rm on rm.rule_id = r.id

+ 28
- 30
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml Datei anzeigen

@@ -9,8 +9,7 @@
oqp.parent_uuid as parentKee,
oqp.last_used as lastUsed,
oqp.user_updated_at as userUpdatedAt,
rp.id as id,
rp.kee as rulesProfileUuid,
rp.uuid as rulesProfileUuid,
rp.name as name,
rp.language as language,
rp.rules_updated_at as rulesUpdatedAt,
@@ -18,17 +17,16 @@
</sql>

<sql id="ruleProfileColumns">
rp.id as id,
rp.kee as kee,
rp.uuid as uuid,
rp.name as name,
rp.language as language,
rp.rules_updated_at as rulesUpdatedAt,
rp.is_built_in as isBuiltIn
</sql>

<insert id="insertRuleProfile" parameterType="map" keyColumn="id" useGeneratedKeys="true" keyProperty="dto.id">
<insert id="insertRuleProfile" parameterType="map" useGeneratedKeys="false">
insert into rules_profiles (
kee,
uuid,
name,
language,
created_at,
@@ -36,7 +34,7 @@
rules_updated_at,
is_built_in
) values (
#{dto.kee, jdbcType=VARCHAR},
#{dto.uuid, jdbcType=VARCHAR},
#{dto.name, jdbcType=VARCHAR},
#{dto.language, jdbcType=VARCHAR},
#{now, jdbcType=TIMESTAMP},
@@ -77,7 +75,7 @@
rules_updated_at = #{dto.rulesUpdatedAt, jdbcType=VARCHAR},
is_built_in = #{dto.isBuiltIn, jdbcType=BOOLEAN}
where
kee = #{dto.kee, jdbcType=VARCHAR}
uuid = #{dto.uuid, jdbcType=VARCHAR}
</update>

<update id="updateOrgQProfile" parameterType="map">
@@ -103,7 +101,7 @@

<delete id="deleteRuleProfilesByUuids" parameterType="String">
delete from rules_profiles
where kee in
where uuid in
<foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
</delete>

@@ -122,14 +120,14 @@
<select id="selectRuleProfile" resultType="org.sonar.db.qualityprofile.RulesProfileDto">
select <include refid="ruleProfileColumns"/>
from rules_profiles rp
where rp.kee = #{uuid, jdbcType=VARCHAR}
where rp.uuid = #{uuid, jdbcType=VARCHAR}
</select>

<select id="selectOrderedByOrganizationUuid" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
where
oqp.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
order by rp.name, rp.language
@@ -139,7 +137,7 @@
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
inner join default_qprofiles dp on dp.qprofile_uuid = oqp.uuid
where
dp.language = #{language, jdbcType=VARCHAR}
@@ -152,7 +150,7 @@
SELECT
<include refid="qProfileColumns"/>
FROM org_qprofiles oqp
INNER JOIN rules_profiles rp ON oqp.rules_profile_uuid = rp.kee
INNER JOIN rules_profiles rp ON oqp.rules_profile_uuid = rp.uuid
INNER JOIN default_qprofiles dp ON dp.qprofile_uuid = oqp.uuid
WHERE
rp.is_built_in = ${_true}
@@ -160,7 +158,7 @@
AND NOT EXISTS (
SELECT 1 FROM active_rules ar
INNER JOIN rules r ON r.id = ar.rule_id AND r.status &lt;&gt; 'REMOVED'
WHERE profile_id=rp.id
WHERE profile_uuid = rp.uuid
)
</select>

@@ -168,7 +166,7 @@
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
inner join default_qprofiles dp on dp.qprofile_uuid = oqp.uuid
where
dp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
@@ -184,7 +182,7 @@
AND EXISTS (
SELECT 1 FROM active_rules ar
INNER JOIN rules r ON r.id = ar.rule_id AND r.status &lt;&gt; 'REMOVED'
WHERE profile_id=rp.id
WHERE profile_uuid=rp.uuid
)
</select>

@@ -192,7 +190,7 @@
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
where
rp.name = #{name, jdbcType=VARCHAR}
and rp.language = #{language, jdbcType=VARCHAR}
@@ -203,9 +201,9 @@
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
where
rp.kee = #{ruleProfileUuid, jdbcType=VARCHAR}
rp.uuid = #{ruleProfileUuid, jdbcType=VARCHAR}
and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>

@@ -213,7 +211,7 @@
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
where
rp.name = #{name, jdbcType=VARCHAR}
and rp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
@@ -224,7 +222,7 @@
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
where
oqp.uuid = #{uuid, jdbcType=VARCHAR}
</select>
@@ -233,7 +231,7 @@
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
where
oqp.uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
</select>
@@ -242,7 +240,7 @@
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
where
rp.language = #{language, jdbcType=VARCHAR}
and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
@@ -252,7 +250,7 @@
<select id="selectChildren" parameterType="string" resultType="org.sonar.db.qualityprofile.QProfileDto">
select <include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
inner join org_qprofiles parent on parent.uuid = oqp.parent_uuid
where
parent.uuid in <foreach collection="uuids" item="uuid" open="(" close=")" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
@@ -278,7 +276,7 @@
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
inner join project_qprofiles pqp ON pqp.profile_key = oqp.uuid
where
rp.language = #{language, jdbcType=VARCHAR}
@@ -290,7 +288,7 @@
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
inner join project_qprofiles pqp ON pqp.profile_key = oqp.uuid
where
rp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
@@ -378,7 +376,7 @@
select oqp.rules_profile_uuid
from org_qprofiles oqp
inner join organizations o on o.uuid = oqp.organization_uuid
inner join rules_profiles rp on rp.kee = oqp.rules_profile_uuid
inner join rules_profiles rp on rp.uuid = oqp.rules_profile_uuid
where
rp.language = #{language, jdbcType=VARCHAR}
and rp.name = #{name, jdbcType=VARCHAR}
@@ -391,16 +389,16 @@
name = #{newName, jdbcType=VARCHAR},
updated_at = #{updatedAt, jdbcType=TIMESTAMP}
where
kee in <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
</update>

<select id="selectQProfilesByRuleProfileUuid" parameterType="string" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
where
rp.kee= #{rulesProfileUuid, jdbcType=VARCHAR}
rp.uuid= #{rulesProfileUuid, jdbcType=VARCHAR}
</select>
</mapper>


+ 6
- 8
server/sonar-db-dao/src/schema/schema-sq.ddl Datei anzeigen

@@ -24,16 +24,16 @@ ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "PK_ACTIVE_RULE_PARAMETERS"
CREATE INDEX "ARP_ACTIVE_RULE_UUID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_UUID");

CREATE TABLE "ACTIVE_RULES"(
"PROFILE_ID" INTEGER NOT NULL,
"RULE_ID" INTEGER NOT NULL,
"FAILURE_LEVEL" INTEGER NOT NULL,
"INHERITANCE" VARCHAR(10),
"CREATED_AT" BIGINT,
"UPDATED_AT" BIGINT,
"UUID" VARCHAR(40) NOT NULL
"UUID" VARCHAR(40) NOT NULL,
"PROFILE_UUID" VARCHAR(40) NOT NULL
);
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 UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_ID");

CREATE TABLE "ALM_APP_INSTALLS"(
"UUID" VARCHAR(40) NOT NULL,
@@ -863,17 +863,15 @@ CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");

CREATE TABLE "RULES_PROFILES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"KEE" VARCHAR(255) NOT NULL,
"IS_BUILT_IN" BOOLEAN NOT NULL,
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
"UPDATED_AT" TIMESTAMP,
"UUID" VARCHAR(40) NOT NULL
);
ALTER TABLE "RULES_PROFILES" ADD CONSTRAINT "PK_RULES_PROFILES" PRIMARY KEY("ID");
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES"("KEE");
ALTER TABLE "RULES_PROFILES" ADD CONSTRAINT "PK_RULES_PROFILES" PRIMARY KEY("UUID");

CREATE TABLE "SNAPSHOTS"(
"UUID" VARCHAR(50) NOT NULL,

+ 10
- 10
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java Datei anzeigen

@@ -147,8 +147,8 @@ public class ActiveRuleDaoTest {
List<OrgActiveRuleDto> result = underTest.selectByProfile(dbSession, profile1);
assertThat(result)
.hasSize(2)
.extracting(OrgActiveRuleDto::getOrganizationUuid, OrgActiveRuleDto::getProfileUuid, OrgActiveRuleDto::getProfileId)
.containsOnly(tuple(organization.getUuid(), profile1.getKee(), profile1.getId()));
.extracting(OrgActiveRuleDto::getOrganizationUuid, OrgActiveRuleDto::getOrgProfileUuid, OrgActiveRuleDto::getProfileUuid)
.containsOnly(tuple(organization.getUuid(), profile1.getKee(), profile1.getRulesProfileUuid()));

assertThat(underTest.selectByProfile(dbSession, profile2)).isEmpty();
}
@@ -169,7 +169,7 @@ public class ActiveRuleDaoTest {
underTest.insert(dbSession, activeRule1);

assertThat(underTest.selectByTypeAndProfileUuids(dbSession, singletonList(RuleType.VULNERABILITY.getDbConstant()), singletonList(profile1.getKee())))
.extracting(OrgActiveRuleDto::getProfileUuid, OrgActiveRuleDto::getOrganizationUuid, OrgActiveRuleDto::getRuleId)
.extracting(OrgActiveRuleDto::getOrgProfileUuid, OrgActiveRuleDto::getOrganizationUuid, OrgActiveRuleDto::getRuleId)
.contains(tuple(profile1.getKee(), profile1.getOrganizationUuid(), rule1.getId()));
}

@@ -195,7 +195,7 @@ public class ActiveRuleDaoTest {
underTest.selectByTypeAndProfileUuids(dbSession,
singletonList(RuleType.VULNERABILITY.getDbConstant()),
singletonList(profile1.getKee())))
.extracting(OrgActiveRuleDto::getProfileUuid, OrgActiveRuleDto::getOrganizationUuid, OrgActiveRuleDto::getRuleId)
.extracting(OrgActiveRuleDto::getOrgProfileUuid, OrgActiveRuleDto::getOrganizationUuid, OrgActiveRuleDto::getRuleId)
.contains(tuple(profile1.getKee(), profile1.getOrganizationUuid(), rule1.getId()));

assertThat(
@@ -215,8 +215,8 @@ public class ActiveRuleDaoTest {
List<ActiveRuleDto> result = underTest.selectByRuleProfile(dbSession, RulesProfileDto.from(profile1));
assertThat(result)
.hasSize(2)
.extracting(ActiveRuleDto::getProfileId, ActiveRuleDto::getRuleKey, ActiveRuleDto::getSeverityString)
.containsOnly(tuple(profile1.getId(), rule1.getKey(), BLOCKER), tuple(profile1.getId(), rule2.getKey(), MAJOR));
.extracting(ActiveRuleDto::getProfileUuid, ActiveRuleDto::getRuleKey, ActiveRuleDto::getSeverityString)
.containsOnly(tuple(profile1.getRulesProfileUuid(), rule1.getKey(), BLOCKER), tuple(profile1.getRulesProfileUuid(), rule2.getKey(), MAJOR));

assertThat(underTest.selectByProfile(dbSession, profile2)).isEmpty();
}
@@ -271,7 +271,7 @@ public class ActiveRuleDaoTest {
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());
assertThat(result.getProfileUuid()).isEqualTo(profile1.getRulesProfileUuid());
assertThat(result.getSeverityString()).isEqualTo(BLOCKER);
assertThat(result.getInheritance()).isEqualTo(INHERITED);
assertThat(result.getCreatedAt()).isEqualTo(1000L);
@@ -283,7 +283,7 @@ public class ActiveRuleDaoTest {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Quality profile is not persisted (missing id)");

underTest.insert(dbSession, createFor(profile1, rule1).setProfileId(null));
underTest.insert(dbSession, createFor(profile1, rule1).setProfileUuid(null));
}

@Test
@@ -325,7 +325,7 @@ public class ActiveRuleDaoTest {
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());
assertThat(result.getProfileUuid()).isEqualTo(profile1.getRulesProfileUuid());
assertThat(result.getSeverityString()).isEqualTo(MAJOR);
assertThat(result.getInheritance()).isEqualTo(OVERRIDES);
assertThat(result.getCreatedAt()).isEqualTo(1000L);
@@ -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).setUuid("uuid").setProfileId(null));
underTest.update(dbSession, createFor(profile1, rule1).setUuid("uuid").setProfileUuid(null));
}

@Test

+ 10
- 12
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java Datei anzeigen

@@ -96,7 +96,6 @@ public class QualityProfileDaoTest {
QProfileDto reloaded = underTest.selectByUuid(dbSession, dto.getKee());
assertThat(reloaded.getKee()).isEqualTo(dto.getKee());
assertThat(reloaded.getRulesProfileUuid()).isEqualTo(dto.getRulesProfileUuid());
assertThat(reloaded.getId()).isNotNull().isNotZero();
assertThat(reloaded.getLanguage()).isEqualTo(dto.getLanguage());
assertThat(reloaded.getName()).isEqualTo(dto.getName());
assertThat(reloaded.getLastUsed()).isEqualTo(dto.getLastUsed());
@@ -192,7 +191,7 @@ public class QualityProfileDaoTest {
public void selectRuleProfile() {
RulesProfileDto rp = insertRulesProfile();

assertThat(underTest.selectRuleProfile(dbSession, rp.getKee()).getId()).isEqualTo(rp.getId());
assertThat(underTest.selectRuleProfile(dbSession, rp.getUuid()).getName()).isEqualTo(rp.getName());
assertThat(underTest.selectRuleProfile(dbSession, "missing")).isNull();
}

@@ -201,11 +200,11 @@ public class QualityProfileDaoTest {
RulesProfileDto rp1 = insertRulesProfile();
RulesProfileDto rp2 = insertRulesProfile();

underTest.deleteRulesProfilesByUuids(dbSession, asList(rp1.getKee()));
underTest.deleteRulesProfilesByUuids(dbSession, asList(rp1.getUuid()));

List<Map<String, Object>> uuids = db.select(dbSession, "select kee as \"uuid\" from rules_profiles");
List<Map<String, Object>> uuids = db.select(dbSession, "select uuid as \"uuid\" from rules_profiles");
assertThat(uuids).hasSize(1);
assertThat(uuids.get(0).get("uuid")).isEqualTo(rp2.getKee());
assertThat(uuids.get(0).get("uuid")).isEqualTo(rp2.getUuid());
}

@Test
@@ -230,7 +229,7 @@ public class QualityProfileDaoTest {
RulesProfileDto dto = new RulesProfileDto()
.setName(randomAlphanumeric(10))
.setLanguage(randomAlphanumeric(3))
.setKee(Uuids.createFast())
.setUuid(Uuids.createFast())
.setIsBuiltIn(false);
db.getDbClient().qualityProfileDao().insert(dbSession, dto);
return dto;
@@ -283,7 +282,7 @@ public class QualityProfileDaoTest {
QProfileDto reloaded = reloadeds.get(i - 1);
QProfileDto original = sharedData.get(i - 1);

assertThat(reloaded.getId()).isEqualTo(original.getId());
assertThat(reloaded.getRulesProfileUuid()).isEqualTo(original.getRulesProfileUuid());
assertThat(reloaded.getName()).isEqualTo(original.getName());
assertThat(reloaded.getKee()).isEqualTo(original.getKee());
assertThat(reloaded.getOrganizationUuid()).isEqualTo(original.getOrganizationUuid());
@@ -406,7 +405,6 @@ public class QualityProfileDaoTest {
assertThat(results).hasSize(1);
QProfileDto result = results.get(0);

assertThat(result.getId()).isEqualTo(profile.getId());
assertThat(result.getName()).isEqualTo(profile.getName());
assertThat(result.getKee()).isEqualTo(profile.getKee());
assertThat(result.getLanguage()).isEqualTo(profile.getLanguage());
@@ -879,10 +877,10 @@ public class QualityProfileDaoTest {
OrganizationDto org2 = db.organizations().insert();

RulesProfileDto ruleProfile1 = QualityProfileTesting.newRuleProfileDto();
OrgQProfileDto profile1InOrg1 = new OrgQProfileDto().setOrganizationUuid(org1.getUuid()).setRulesProfileUuid(ruleProfile1.getKee()).setUuid(Uuids.create());
OrgQProfileDto profile1InOrg2 = new OrgQProfileDto().setOrganizationUuid(org2.getUuid()).setRulesProfileUuid(ruleProfile1.getKee()).setUuid(Uuids.create());
OrgQProfileDto profile1InOrg1 = new OrgQProfileDto().setOrganizationUuid(org1.getUuid()).setRulesProfileUuid(ruleProfile1.getUuid()).setUuid(Uuids.create());
OrgQProfileDto profile1InOrg2 = new OrgQProfileDto().setOrganizationUuid(org2.getUuid()).setRulesProfileUuid(ruleProfile1.getUuid()).setUuid(Uuids.create());
RulesProfileDto ruleProfile2 = QualityProfileTesting.newRuleProfileDto();
OrgQProfileDto profile2InOrg1 = new OrgQProfileDto().setOrganizationUuid(org1.getUuid()).setRulesProfileUuid(ruleProfile2.getKee()).setUuid(Uuids.create());
OrgQProfileDto profile2InOrg1 = new OrgQProfileDto().setOrganizationUuid(org1.getUuid()).setRulesProfileUuid(ruleProfile2.getUuid()).setUuid(Uuids.create());
db.getDbClient().qualityProfileDao().insert(db.getSession(), ruleProfile1);
db.getDbClient().qualityProfileDao().insert(db.getSession(), profile1InOrg1);
db.getDbClient().qualityProfileDao().insert(db.getSession(), profile1InOrg2);
@@ -898,7 +896,7 @@ public class QualityProfileDaoTest {

@Test
public void selectQProfilesByRuleProfileUuid_returns_empty_list_if_rule_profile_does_not_exist() {
List<QProfileDto> result = db.getDbClient().qualityProfileDao().selectQProfilesByRuleProfile(db.getSession(), new RulesProfileDto().setKee("unknown"));
List<QProfileDto> result = db.getDbClient().qualityProfileDao().selectQProfilesByRuleProfile(db.getSession(), new RulesProfileDto().setUuid("unknown"));

assertThat(result).isEmpty();
}

+ 1
- 1
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileTesting.java Datei anzeigen

@@ -65,7 +65,7 @@ public class QualityProfileTesting {
*/
public static RulesProfileDto newRuleProfileDto(Consumer<RulesProfileDto>... populators) {
RulesProfileDto dto = new RulesProfileDto()
.setKee("uuid" + randomAlphabetic(10))
.setUuid("uuid" + randomAlphabetic(10))
.setName("name" + randomAlphabetic(10))
.setLanguage("lang" + randomAlphabetic(5))
.setIsBuiltIn(false);

+ 44
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java Datei anzeigen

@@ -187,6 +187,22 @@ import org.sonar.server.platform.db.migration.version.v83.qualitygateconditions.
import org.sonar.server.platform.db.migration.version.v83.qualitygateconditions.DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable;
import org.sonar.server.platform.db.migration.version.v83.qualitygateconditions.MakeQualityGateConditionsUuidColumnNotNullable;
import org.sonar.server.platform.db.migration.version.v83.qualitygateconditions.PopulateQualityGateConditionsUuid;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.AddPrimaryKeyOnUuidColumnOfRulesProfilesTable;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.AddUuidColumnToRulesProfilesTable;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.DropIdColumnOfRulesProfilesTable;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.DropKeeColumnOfRulesProfilesTable;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.DropPrimaryKeyOnIdColumnOfRulesProfilesTable;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.DropUniqueIndexOnKeeColumnOfRulesProfilesTable;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.MakeRulesProfilesUuidColumnNotNullable;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.PopulateRulesProfilesUuid;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.fk.activerules.AddProfileUuidColumnToActiveRulesTable;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.fk.activerules.AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.fk.activerules.DropProfileIdColumnOfActiveRulesTable;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.fk.activerules.DropUniqueIndexOnProfileIdColumnOfActiveRulesTable;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.fk.activerules.MakeActiveRulesProfileUuidColumnNotNullable;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.fk.activerules.PopulateActiveRulesProfileUuid;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.fk.orgqprofiles.PopulateOrgQProfilesRulesProfileUuid;
import org.sonar.server.platform.db.migration.version.v83.rulesprofiles.fk.qprofilechanges.PopulateQProfileChangesRulesProfileUuid;
import org.sonar.server.platform.db.migration.version.v83.snapshots.issues.AddPrimaryKeyOnUuidColumnOfSnapshotsTable;
import org.sonar.server.platform.db.migration.version.v83.snapshots.issues.DropIdColumnOfSnapshotsTable;
import org.sonar.server.platform.db.migration.version.v83.snapshots.issues.DropPrimaryKeyOnIdColumnOfSnapshotsTable;
@@ -475,6 +491,34 @@ public class DbVersion83 implements DbVersion {
.add(3573, "Drop column 'ID' of 'PERMISSION_TEMPLATES' table", DropIdColumnOfPermissionTemplatesTable.class)
.add(3574, "Drop column 'KEE' of 'PERMISSION_TEMPLATES' table", DropKeeColumnOfPermissionTemplatesTable.class)

// Migration on RULES_PROFILES table
.add(3575, "Add 'uuid' column for 'RULES_PROFILES'", AddUuidColumnToRulesProfilesTable.class)
.add(3576, "Populate 'uuid' column for 'RULES_PROFILES'", PopulateRulesProfilesUuid.class)
.add(3577, "Make 'uuid' column not nullable for 'RULES_PROFILES'", MakeRulesProfilesUuidColumnNotNullable.class)

// Migration of ORG_QPROFILES FK to RULES_PROFILES
.add(3578, "Populate 'rules_profile_uuid' column for 'ORG_QPROFILES' table", PopulateOrgQProfilesRulesProfileUuid.class)

// Migration of QPROFILE_CHANGES FK to RULES_PROFILES
.add(3579, "Populate 'rules_profile_uuid' column for 'QPROFILE_CHANGES' table", PopulateQProfileChangesRulesProfileUuid.class)

// Migration of ACTIVE_RULES FK to RULES_PROFILES, switch from profile_id to profile_uuid
.add(3580, "Add 'profile_uuid' column for 'ACTIVE_RULES' table", AddProfileUuidColumnToActiveRulesTable.class)
.add(3581, "Populate 'profile_uuid' column for 'ACTIVE_RULES' table", PopulateActiveRulesProfileUuid.class)
.add(3582, "Make 'profile_uuid' column not nullable for 'ACTIVE_RULES' table", MakeActiveRulesProfileUuidColumnNotNullable.class)

.add(3583, "Drop unique constraint on 'profile_id', 'rule_id' columns 'ACTIVE_RULES' table", DropUniqueIndexOnProfileIdColumnOfActiveRulesTable.class)
.add(3584, "Add unique constraint on 'profile_uuid', 'rule_id' columns 'ACTIVE_RULES' table", AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable.class)

.add(3585, "Drop column 'profile_id' of 'ACTIVE_RULES' table", DropProfileIdColumnOfActiveRulesTable.class)

.add(3586, "Drop unique constraint on 'kee' columns 'RULES_PROFILES' table", DropUniqueIndexOnKeeColumnOfRulesProfilesTable.class)
.add(3587, "Drop column 'kee' of 'RULES_PROFILES' table", DropKeeColumnOfRulesProfilesTable.class)

.add(3588, "Drop primary key on 'ID' column of 'RULES_PROFILES' table", DropPrimaryKeyOnIdColumnOfRulesProfilesTable.class)
.add(3589, "Add primary key on 'UUID' column of 'RULES_PROFILES' table", AddPrimaryKeyOnUuidColumnOfRulesProfilesTable.class)
.add(3590, "Drop column 'ID' of 'RULES_PROFILES' table", DropIdColumnOfRulesProfilesTable.class)

;
}
}

+ 38
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTable.java Datei anzeigen

@@ -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.rulesprofiles;

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 AddPrimaryKeyOnUuidColumnOfRulesProfilesTable extends DdlChange {

public AddPrimaryKeyOnUuidColumnOfRulesProfilesTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddPrimaryKeyBuilder("rules_profiles", "uuid").build());
}

}

+ 31
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTable.java Datei anzeigen

@@ -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.rulesprofiles;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable;

public class AddUuidColumnToRulesProfilesTable extends AddUuidColumnToTable {
private static final String TABLE = "rules_profiles";

public AddUuidColumnToRulesProfilesTable(Database db) {
super(db, TABLE);
}
}

+ 33
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTable.java Datei anzeigen

@@ -0,0 +1,33 @@
/*
* 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.rulesprofiles;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.version.v83.common.DropIdColumn;

public class DropIdColumnOfRulesProfilesTable extends DropIdColumn {

private static final String TABLE_NAME = "rules_profiles";

public DropIdColumnOfRulesProfilesTable(Database db) {
super(db, TABLE_NAME);
}

}

+ 41
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTable.java Datei anzeigen

@@ -0,0 +1,41 @@
/*
* 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.rulesprofiles;

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 DropKeeColumnOfRulesProfilesTable extends DdlChange {

private Database db;

public DropKeeColumnOfRulesProfilesTable(Database db) {
super(db);
this.db = db;
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropColumnsBuilder(db.getDialect(), "rules_profiles", "kee").build());
}

}

+ 32
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTable.java Datei anzeigen

@@ -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.rulesprofiles;

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 DropPrimaryKeyOnIdColumnOfRulesProfilesTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "rules_profiles";

public DropPrimaryKeyOnIdColumnOfRulesProfilesTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
super(db, dropPrimaryKeySqlGenerator, TABLE_NAME);
}
}

+ 52
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTable.java Datei anzeigen

@@ -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.rulesprofiles;

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 DropUniqueIndexOnKeeColumnOfRulesProfilesTable extends DdlChange {
private static final String TABLE_NAME = "rules_profiles";
private static final String INDEX_NAME = "uniq_qprof_key";

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

+ 32
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullable.java Datei anzeigen

@@ -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.rulesprofiles;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.version.v83.common.MakeUuidColumnNotNullable;

public class MakeRulesProfilesUuidColumnNotNullable extends MakeUuidColumnNotNullable {
private static final String TABLE_NAME = "rules_profiles";

public MakeRulesProfilesUuidColumnNotNullable(Database db) {
super(db, TABLE_NAME);
}

}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuid.java Datei anzeigen

@@ -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.rulesprofiles;

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 PopulateRulesProfilesUuid extends DataChange {

private final UuidFactory uuidFactory;

public PopulateRulesProfilesUuid(Database db, UuidFactory uuidFactory) {
super(db);
this.uuidFactory = uuidFactory;
}

@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();

massUpdate.select("select id from rules_profiles where uuid is null");
massUpdate.update("update rules_profiles set uuid = ? where id = ?");

massUpdate.execute((row, update) -> {
update.setString(1, uuidFactory.create());
update.setLong(2, row.getLong(1));
return true;
});
}
}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTable.java Datei anzeigen

@@ -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.rulesprofiles.fk.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 AddProfileUuidColumnToActiveRulesTable extends DdlChange {
private static final String TABLE = "active_rules";

private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
.setColumnName("profile_uuid")
.setIsNullable(true)
.setDefaultValue(null)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build();

public AddProfileUuidColumnToActiveRulesTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDialect(), TABLE)
.addColumn(uuidColumnDefinition)
.build());
}
}

+ 67
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable.java Datei anzeigen

@@ -0,0 +1,67 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.rulesprofiles.fk.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.IntegerColumnDef;
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 AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable extends DdlChange {
private static final String TABLE_NAME = "active_rules";
private static final String INDEX_NAME = "uniq_profile_rule_ids";

public AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
if (!indexExists()) {
context.execute(new CreateIndexBuilder()
.setUnique(true)
.setTable(TABLE_NAME)
.setName(INDEX_NAME)
.addColumn(newVarcharColumnDefBuilder()
.setColumnName("profile_uuid")
.setIsNullable(false)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build())
.addColumn(IntegerColumnDef.newIntegerColumnDefBuilder()
.setColumnName("rule_id")
.setIsNullable(false)
.build())
.build());
}

}

private boolean indexExists() throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
}
}
}

+ 41
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTable.java Datei anzeigen

@@ -0,0 +1,41 @@
/*
* 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.rulesprofiles.fk.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 DropProfileIdColumnOfActiveRulesTable extends DdlChange {

private Database db;

public DropProfileIdColumnOfActiveRulesTable(Database db) {
super(db);
this.db = db;
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropColumnsBuilder(db.getDialect(), "active_rules", "profile_id").build());
}

}

+ 52
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTable.java Datei anzeigen

@@ -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.rulesprofiles.fk.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 DropUniqueIndexOnProfileIdColumnOfActiveRulesTable extends DdlChange {
private static final String TABLE_NAME = "active_rules";
private static final String INDEX_NAME = "uniq_profile_rule_ids";

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

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullable.java Datei anzeigen

@@ -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.rulesprofiles.fk.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 MakeActiveRulesProfileUuidColumnNotNullable extends DdlChange {
private static final String TABLE = "active_rules";

private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
.setColumnName("profile_uuid")
.setIsNullable(false)
.setDefaultValue(null)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build();

public MakeActiveRulesProfileUuidColumnNotNullable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
.updateColumn(uuidColumnDefinition)
.build());
}
}

+ 49
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuid.java Datei anzeigen

@@ -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.rulesprofiles.fk.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 PopulateActiveRulesProfileUuid extends DataChange {

public PopulateActiveRulesProfileUuid(Database db) {
super(db);
}

@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();

massUpdate.select("select ar.uuid, rp.uuid " +
"from active_rules ar " +
"join rules_profiles rp on ar.profile_id = rp.id " +
"where ar.profile_uuid is null");
massUpdate.update("update active_rules set profile_uuid = ? where uuid = ?");

massUpdate.execute((row, update) -> {
update.setString(1, row.getString(2));
update.setString(2, row.getString(1));
return true;
});
}
}

+ 48
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuid.java Datei anzeigen

@@ -0,0 +1,48 @@
/*
* 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.rulesprofiles.fk.orgqprofiles;

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 PopulateOrgQProfilesRulesProfileUuid extends DataChange {

public PopulateOrgQProfilesRulesProfileUuid(Database db) {
super(db);
}

@Override
protected void execute(DataChange.Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();

massUpdate.select("select oqp.uuid, rp.uuid " +
"from org_qprofiles oqp " +
"join rules_profiles rp on oqp.rules_profile_uuid = rp.kee");
massUpdate.update("update org_qprofiles set rules_profile_uuid = ? where uuid = ?");

massUpdate.execute((row, update) -> {
update.setString(1, row.getString(2));
update.setString(2, row.getString(1));
return true;
});
}
}

+ 48
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuid.java Datei anzeigen

@@ -0,0 +1,48 @@
/*
* 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.rulesprofiles.fk.qprofilechanges;

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 PopulateQProfileChangesRulesProfileUuid extends DataChange {

public PopulateQProfileChangesRulesProfileUuid(Database db) {
super(db);
}

@Override
protected void execute(DataChange.Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();

massUpdate.select("select qpc.kee, rp.uuid " +
"from qprofile_changes qpc " +
"join rules_profiles rp on qpc.rules_profile_uuid = rp.kee");
massUpdate.update("update qprofile_changes set rules_profile_uuid = ? where kee = ?");

massUpdate.execute((row, update) -> {
update.setString(1, row.getString(2));
update.setString(2, row.getString(1));
return true;
});
}
}

+ 49
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest.java Datei anzeigen

@@ -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.rulesprofiles;

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 AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest {
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest.class, "schema.sql");

private DdlChange underTest = new AddPrimaryKeyOnUuidColumnOfRulesProfilesTable(db.database());

@Test
public void execute() throws SQLException {
underTest.execute();

db.assertPrimaryKey("rules_profiles", "pk_rules_profiles", "uuid");
}

@Test
public void migration_is_not_re_entrant() throws SQLException {
underTest.execute();

assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
}
}

+ 67
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTableTest.java Datei anzeigen

@@ -0,0 +1,67 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.rulesprofiles;

import java.sql.SQLException;
import java.sql.Types;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.core.util.UuidFactory;
import org.sonar.core.util.UuidFactoryFast;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.assertj.core.api.Assertions.assertThat;

public class AddUuidColumnToRulesProfilesTableTest {

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToRulesProfilesTableTest.class, "schema.sql");

private UuidFactory uuidFactory = UuidFactoryFast.getInstance();

private DdlChange underTest = new AddUuidColumnToRulesProfilesTable(db.database());

@Before
public void setup() {
insertRuleProfile(1L);
insertRuleProfile(2L);
insertRuleProfile(3L);
}

@Test
public void add_uuid_column_to_rules_profiles() throws SQLException {
underTest.execute();

db.assertColumnDefinition("rules_profiles", "uuid", Types.VARCHAR, 40, true);

assertThat(db.countSql("select count(id) from rules_profiles"))
.isEqualTo(3);
}

private void insertRuleProfile(Long id) {
db.executeInsert("rules_profiles",
"id", id,
"name", "name" + id,
"kee", "kee" + id,
"is_built_in", false);
}
}

+ 49
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTableTest.java Datei anzeigen

@@ -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.rulesprofiles;

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 DropIdColumnOfRulesProfilesTableTest {
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfRulesProfilesTableTest.class, "schema.sql");

private DdlChange underTest = new DropIdColumnOfRulesProfilesTable(db.database());

@Test
public void execute() throws SQLException {
underTest.execute();

db.assertColumnDoesNotExist("rules_profiles", "id");
}

@Test
public void migration_is_not_re_entrant() throws SQLException {
underTest.execute();

assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
}
}

+ 49
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTableTest.java Datei anzeigen

@@ -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.rulesprofiles;

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 DropKeeColumnOfRulesProfilesTableTest {
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropKeeColumnOfRulesProfilesTableTest.class, "schema.sql");

private DdlChange underTest = new DropKeeColumnOfRulesProfilesTable(db.database());

@Test
public void execute() throws SQLException {
underTest.execute();

db.assertColumnDoesNotExist("rules_profiles", "kee");
}

@Test
public void migration_is_not_re_entrant() throws SQLException {
underTest.execute();

assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
}
}

+ 54
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.java Datei anzeigen

@@ -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.rulesprofiles;

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 DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest {
private static final String TABLE_NAME = "rules_profiles";
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.class, "schema.sql");

private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));

private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfRulesProfilesTable(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);
}
}

+ 54
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest.java Datei anzeigen

@@ -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.rulesprofiles;

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;

public class DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest {

private static final String TABLE_NAME = "rules_profiles";
private static final String INDEX_NAME = "uniq_qprof_key";

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest.class, "schema.sql");

private DdlChange underTest = new DropUniqueIndexOnKeeColumnOfRulesProfilesTable(db.database());

@Test
public void execute() throws SQLException {
underTest.execute();

db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
}

@Test
public void migration_is_re_entrant() throws SQLException {
underTest.execute();
// migration is re-entrant
underTest.execute();

db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
}

}

+ 43
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullableTest.java Datei anzeigen

@@ -0,0 +1,43 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.rulesprofiles;

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 MakeRulesProfilesUuidColumnNotNullableTest {

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(MakeRulesProfilesUuidColumnNotNullableTest.class, "schema.sql");

private MigrationStep underTest = new MakeRulesProfilesUuidColumnNotNullable(db.database());

@Test
public void uuid_column_is_not_null() throws SQLException {
underTest.execute();

db.assertColumnDefinition("rules_profiles", "uuid", VARCHAR, null, false);
}
}

+ 81
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuidTest.java Datei anzeigen

@@ -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.rulesprofiles;

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 PopulateRulesProfilesUuidTest {

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(PopulateRulesProfilesUuidTest.class, "schema.sql");

private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
private DataChange underTest = new PopulateRulesProfilesUuid(db.database(), uuidFactory);

@Test
public void populate_uuids() throws SQLException {
insertRuleProfile(1L);
insertRuleProfile(2L);
insertRuleProfile(3L);

underTest.execute();

verifyUuidsAreNotNull();
}

@Test
public void migration_is_reentrant() throws SQLException {
insertRuleProfile(1L);
insertRuleProfile(2L);
insertRuleProfile(3L);

underTest.execute();
// re-entrant
underTest.execute();

verifyUuidsAreNotNull();
}

private void verifyUuidsAreNotNull() {
assertThat(db.select("select uuid from rules_profiles")
.stream()
.map(row -> row.get("UUID"))
.filter(Objects::isNull)
.collect(Collectors.toList())).isEmpty();
}

private void insertRuleProfile(Long id) {
db.executeInsert("rules_profiles",
"id", id,
"name", "name" + id,
"kee", "kee" + id,
"is_built_in", false);
}
}

+ 63
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTableTest.java Datei anzeigen

@@ -0,0 +1,63 @@
/*
* 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.rulesprofiles.fk.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 AddProfileUuidColumnToActiveRulesTableTest {

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(AddProfileUuidColumnToActiveRulesTableTest.class, "schema.sql");

private DdlChange underTest = new AddProfileUuidColumnToActiveRulesTable(db.database());

@Before
public void setup() {
insertActiveRule("1", 1L, 2L);
insertActiveRule("2", 3L, 4L);
insertActiveRule("3", 5L, 6L);
}

@Test
public void add_uuid_column_to_rules_profiles() throws SQLException {
underTest.execute();

db.assertColumnDefinition("active_rules", "profile_uuid", Types.VARCHAR, 40, true);

assertThat(db.countRowsOfTable("active_rules"))
.isEqualTo(3);
}

private void insertActiveRule(String uuid, long profileId, long rule_id) {
db.executeInsert("active_rules",
"uuid", uuid,
"profile_id", profileId,
"rule_id", rule_id,
"failure_level", 3);
}
}

+ 51
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest.java Datei anzeigen

@@ -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.rulesprofiles.fk.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 AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest {

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest.class, "schema.sql");

private MigrationStep underTest = new AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable(db.database());

@Test
public void execute() throws SQLException {
underTest.execute();

db.assertUniqueIndex("active_rules", "uniq_profile_rule_ids", "profile_uuid", "rule_id");
}

@Test
public void migration_is_re_entrant() throws SQLException {
underTest.execute();
// re-entrant
underTest.execute();

db.assertUniqueIndex("active_rules", "uniq_profile_rule_ids", "profile_uuid", "rule_id");
}

}

+ 49
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTableTest.java Datei anzeigen

@@ -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.rulesprofiles.fk.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 DropProfileIdColumnOfActiveRulesTableTest {
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropProfileIdColumnOfActiveRulesTableTest.class, "schema.sql");

private DdlChange underTest = new DropProfileIdColumnOfActiveRulesTable(db.database());

@Test
public void execute() throws SQLException {
underTest.execute();

db.assertColumnDoesNotExist("active_rules", "profile_id");
}

@Test
public void migration_is_not_re_entrant() throws SQLException {
underTest.execute();

assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
}
}

+ 51
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest.java Datei anzeigen

@@ -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.rulesprofiles.fk.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 DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest {
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest.class, "schema.sql");

private MigrationStep underTest = new DropUniqueIndexOnProfileIdColumnOfActiveRulesTable(db.database());

@Test
public void execute() throws SQLException {
underTest.execute();

db.assertIndexDoesNotExist("perm_tpl_characteristics", "uniq_perm_tpl_charac");
}

@Test
public void migration_is_re_entrant() throws SQLException {
underTest.execute();

// re-entrant
underTest.execute();

db.assertIndexDoesNotExist("perm_tpl_characteristics", "uniq_perm_tpl_charac");
}

}

+ 43
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullableTest.java Datei anzeigen

@@ -0,0 +1,43 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.rulesprofiles.fk.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 MakeActiveRulesProfileUuidColumnNotNullableTest {

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(MakeActiveRulesProfileUuidColumnNotNullableTest.class, "schema.sql");

private MigrationStep underTest = new MakeActiveRulesProfileUuidColumnNotNullable(db.database());

@Test
public void uuid_column_is_not_null() throws SQLException {
underTest.execute();

db.assertColumnDefinition("active_rules", "profile_uuid", VARCHAR, null, false);
}
}

+ 113
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuidTest.java Datei anzeigen

@@ -0,0 +1,113 @@
/*
* 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.rulesprofiles.fk.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.DataChange;

import static org.assertj.core.api.Assertions.assertThat;

public class PopulateActiveRulesProfileUuidTest {

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(PopulateActiveRulesProfileUuidTest.class, "schema.sql");

private DataChange underTest = new PopulateActiveRulesProfileUuid(db.database());

@Test
public void populate_uuids() throws SQLException {
long ruleProfileId_1 = 1L;
String ruleProfileUuid_1 = "uuid-1";
insertRuleProfile(ruleProfileId_1, ruleProfileUuid_1);

long ruleProfileId_2 = 2L;
String ruleProfileUuid_2 = "uuid-2";
insertRuleProfile(ruleProfileId_2, ruleProfileUuid_2);

long ruleProfileId_3 = 3L;
String ruleProfileUuid_3 = "uuid-3";
insertRuleProfile(ruleProfileId_3, ruleProfileUuid_3);

insertActiveRule("4", ruleProfileId_1);
insertActiveRule("5", ruleProfileId_2);
insertActiveRule("6", ruleProfileId_3);

underTest.execute();

assertThatActiveRulesProfileUuidIsEqualTo("4", ruleProfileUuid_1);
assertThatActiveRulesProfileUuidIsEqualTo("5", ruleProfileUuid_2);
assertThatActiveRulesProfileUuidIsEqualTo("6", ruleProfileUuid_3);
}

@Test
public void migration_is_reentrant() throws SQLException {
long ruleProfileId_1 = 1L;
String ruleProfileUuid_1 = "uuid-1";
insertRuleProfile(ruleProfileId_1, ruleProfileUuid_1);

long ruleProfileId_2 = 2L;
String ruleProfileUuid_2 = "uuid-2";
insertRuleProfile(ruleProfileId_2, ruleProfileUuid_2);

long ruleProfileId_3 = 3L;
String ruleProfileUuid_3 = "uuid-3";
insertRuleProfile(ruleProfileId_3, ruleProfileUuid_3);

insertActiveRule("4", ruleProfileId_1);
insertActiveRule("5", ruleProfileId_2);
insertActiveRule("6", ruleProfileId_3);

underTest.execute();
// re-entrant
underTest.execute();

assertThatActiveRulesProfileUuidIsEqualTo("4", ruleProfileUuid_1);
assertThatActiveRulesProfileUuidIsEqualTo("5", ruleProfileUuid_2);
assertThatActiveRulesProfileUuidIsEqualTo("6", ruleProfileUuid_3);
}

private void assertThatActiveRulesProfileUuidIsEqualTo(String uuid, String expectedUuid) {
assertThat(db.select("select profile_uuid from active_rules where uuid = '" + uuid + "'")
.stream()
.map(row -> row.get("PROFILE_UUID"))
.findFirst())
.hasValue(expectedUuid);
}

private void insertActiveRule(String uuid, Long profileId) {
db.executeInsert("active_rules",
"uuid", uuid,
"profile_id", profileId,
"rule_id", 1,
"failure_level", 2);
}

private void insertRuleProfile(Long id, String uuid) {
db.executeInsert("rules_profiles",
"id", id,
"uuid", uuid,
"name", "name" + id,
"kee", "kee" + id,
"is_built_in", false);
}
}

+ 137
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuidTest.java Datei anzeigen

@@ -0,0 +1,137 @@
/*
* 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.rulesprofiles.fk.orgqprofiles;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.core.util.Uuids;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DataChange;

import static org.assertj.core.api.Assertions.assertThat;

public class PopulateOrgQProfilesRulesProfileUuidTest {

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(PopulateOrgQProfilesRulesProfileUuidTest.class, "schema.sql");

private DataChange underTest = new PopulateOrgQProfilesRulesProfileUuid(db.database());

@Test
public void populate_uuids() throws SQLException {
long ruleProfileId_1 = 1L;
String ruleProfileUuid_1 = "uuid-1";
String ruleProfileKee_1 = "kee-1";
insertRuleProfile(ruleProfileId_1, ruleProfileUuid_1, ruleProfileKee_1);

long ruleProfileId_2 = 2L;
String ruleProfileUuid_2 = "uuid-2";
String ruleProfileKee_2 = "kee-2";
insertRuleProfile(ruleProfileId_2, ruleProfileUuid_2, ruleProfileKee_2);

long ruleProfileId_3 = 3L;
String ruleProfileUuid_3 = "uuid-3";
String ruleProfileKee_3 = "kee-3";
insertRuleProfile(ruleProfileId_3, ruleProfileUuid_3, ruleProfileKee_3);

String orgQProfileUuid_1 = "orgQProfileUuid_1";
insertOrgQProfiles(orgQProfileUuid_1, ruleProfileKee_1);
String orgQProfileUuid_2 = "orgQProfileUuid_2";
insertOrgQProfiles(orgQProfileUuid_2, ruleProfileKee_2);
String orgQProfileUuid_3 = "orgQProfileUuid_3";
insertOrgQProfiles(orgQProfileUuid_3, ruleProfileKee_3);

underTest.execute();

assertThatOrgQprofileRulesProfileUuidIsEqualTo(orgQProfileUuid_1, ruleProfileUuid_1);
assertThatOrgQprofileRulesProfileUuidIsEqualTo(orgQProfileUuid_2, ruleProfileUuid_2);
assertThatOrgQprofileRulesProfileUuidIsEqualTo(orgQProfileUuid_3, ruleProfileUuid_3);
}

@Test
public void migration_is_reentrant() throws SQLException {
long ruleProfileId_1 = 1L;
String ruleProfileUuid_1 = "uuid-1";
String ruleProfileKee_1 = "kee-1";
insertRuleProfile(ruleProfileId_1, ruleProfileUuid_1, ruleProfileKee_1);

long ruleProfileId_2 = 2L;
String ruleProfileUuid_2 = "uuid-2";
String ruleProfileKee_2 = "kee-2";
insertRuleProfile(ruleProfileId_2, ruleProfileUuid_2, ruleProfileKee_2);

long ruleProfileId_3 = 3L;
String ruleProfileUuid_3 = "uuid-3";
String ruleProfileKee_3 = "kee-3";
insertRuleProfile(ruleProfileId_3, ruleProfileUuid_3, ruleProfileKee_3);

String orgQProfileUuid_1 = "orgQProfileUuid_1";
insertOrgQProfiles(orgQProfileUuid_1, ruleProfileKee_1);
String orgQProfileUuid_2 = "orgQProfileUuid_2";
insertOrgQProfiles(orgQProfileUuid_2, ruleProfileKee_2);
String orgQProfileUuid_3 = "orgQProfileUuid_3";
insertOrgQProfiles(orgQProfileUuid_3, ruleProfileKee_3);

underTest.execute();

long ruleProfileId_4 = 4L;
String ruleProfileUuid_4 = "uuid-4";
String ruleProfileKee_4 = "kee-4";
insertRuleProfile(ruleProfileId_4, ruleProfileUuid_4, ruleProfileKee_4);

String orgQProfileUuid_4 = "orgQProfileUuid_4";
insertOrgQProfiles(orgQProfileUuid_4, ruleProfileKee_4);

// re-entrant
underTest.execute();

assertThatOrgQprofileRulesProfileUuidIsEqualTo(orgQProfileUuid_1, ruleProfileUuid_1);
assertThatOrgQprofileRulesProfileUuidIsEqualTo(orgQProfileUuid_2, ruleProfileUuid_2);
assertThatOrgQprofileRulesProfileUuidIsEqualTo(orgQProfileUuid_3, ruleProfileUuid_3);
assertThatOrgQprofileRulesProfileUuidIsEqualTo(orgQProfileUuid_4, ruleProfileUuid_4);
}

private void assertThatOrgQprofileRulesProfileUuidIsEqualTo(String orgQprofileUuid, String expectedUuid) {
assertThat(db.select("select rules_profile_uuid from org_qprofiles where uuid = '" + orgQprofileUuid + "'")
.stream()
.map(row -> row.get("RULES_PROFILE_UUID"))
.findFirst())
.hasValue(expectedUuid);
}

private void insertOrgQProfiles(String uuid, String rulesProfileUuid) {
db.executeInsert("org_qprofiles",
"uuid", uuid,
"organization_uuid", Uuids.createFast(),
"rules_profile_uuid", rulesProfileUuid,
"created_at", System.currentTimeMillis(),
"updated_at", System.currentTimeMillis());
}

private void insertRuleProfile(Long id, String uuid, String kee) {
db.executeInsert("rules_profiles",
"id", id,
"uuid", uuid,
"name", "name" + id,
"kee", kee,
"is_built_in", false);
}
}

+ 136
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuidTest.java Datei anzeigen

@@ -0,0 +1,136 @@
/*
* 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.rulesprofiles.fk.qprofilechanges;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.core.util.Uuids;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DataChange;

import static org.assertj.core.api.Assertions.assertThat;

public class PopulateQProfileChangesRulesProfileUuidTest {

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(PopulateQProfileChangesRulesProfileUuidTest.class, "schema.sql");

private DataChange underTest = new PopulateQProfileChangesRulesProfileUuid(db.database());

@Test
public void populate_uuids() throws SQLException {
long ruleProfileId_1 = 1L;
String ruleProfileUuid_1 = "uuid-1";
String ruleProfileKee_1 = "kee-1";
insertRuleProfile(ruleProfileId_1, ruleProfileUuid_1, ruleProfileKee_1);

long ruleProfileId_2 = 2L;
String ruleProfileUuid_2 = "uuid-2";
String ruleProfileKee_2 = "kee-2";
insertRuleProfile(ruleProfileId_2, ruleProfileUuid_2, ruleProfileKee_2);

long ruleProfileId_3 = 3L;
String ruleProfileUuid_3 = "uuid-3";
String ruleProfileKee_3 = "kee-3";
insertRuleProfile(ruleProfileId_3, ruleProfileUuid_3, ruleProfileKee_3);

String qProfileChangeUuid_1 = "qProfileChangeUuid_1";
insertQProfileChange(qProfileChangeUuid_1, ruleProfileKee_1);
String qProfileChangeUuid_2 = "qProfileChangeUuid_2";
insertQProfileChange(qProfileChangeUuid_2, ruleProfileKee_2);
String qProfileChangeUuid_3 = "qProfileChangeUuid_3";
insertQProfileChange(qProfileChangeUuid_3, ruleProfileKee_3);

underTest.execute();

assertThatQProfileChangeRulesProfileUuidIsEqualTo(qProfileChangeUuid_1, ruleProfileUuid_1);
assertThatQProfileChangeRulesProfileUuidIsEqualTo(qProfileChangeUuid_2, ruleProfileUuid_2);
assertThatQProfileChangeRulesProfileUuidIsEqualTo(qProfileChangeUuid_3, ruleProfileUuid_3);
}

@Test
public void migration_is_reentrant() throws SQLException {
long ruleProfileId_1 = 1L;
String ruleProfileUuid_1 = "uuid-1";
String ruleProfileKee_1 = "kee-1";
insertRuleProfile(ruleProfileId_1, ruleProfileUuid_1, ruleProfileKee_1);

long ruleProfileId_2 = 2L;
String ruleProfileUuid_2 = "uuid-2";
String ruleProfileKee_2 = "kee-2";
insertRuleProfile(ruleProfileId_2, ruleProfileUuid_2, ruleProfileKee_2);

long ruleProfileId_3 = 3L;
String ruleProfileUuid_3 = "uuid-3";
String ruleProfileKee_3 = "kee-3";
insertRuleProfile(ruleProfileId_3, ruleProfileUuid_3, ruleProfileKee_3);

String qProfileChangeUuid_1 = "qProfileChangeUuid_1";
insertQProfileChange(qProfileChangeUuid_1, ruleProfileKee_1);
String qProfileChangeUuid_2 = "qProfileChangeUuid_2";
insertQProfileChange(qProfileChangeUuid_2, ruleProfileKee_2);
String qProfileChangeUuid_3 = "qProfileChangeUuid_3";
insertQProfileChange(qProfileChangeUuid_3, ruleProfileKee_3);

underTest.execute();

long ruleProfileId_4 = 4L;
String ruleProfileUuid_4 = "uuid-4";
String ruleProfileKee_4 = "kee-4";
insertRuleProfile(ruleProfileId_4, ruleProfileUuid_4, ruleProfileKee_4);

String qProfileChangeUuid_4 = "qProfileChangeUuid_4";
insertQProfileChange(qProfileChangeUuid_4, ruleProfileKee_4);

// re-entrant
underTest.execute();

assertThatQProfileChangeRulesProfileUuidIsEqualTo(qProfileChangeUuid_1, ruleProfileUuid_1);
assertThatQProfileChangeRulesProfileUuidIsEqualTo(qProfileChangeUuid_2, ruleProfileUuid_2);
assertThatQProfileChangeRulesProfileUuidIsEqualTo(qProfileChangeUuid_3, ruleProfileUuid_3);
assertThatQProfileChangeRulesProfileUuidIsEqualTo(qProfileChangeUuid_4, ruleProfileUuid_4);
}

private void assertThatQProfileChangeRulesProfileUuidIsEqualTo(String qProfileChangeKee, String expectedUuid) {
assertThat(db.select("select rules_profile_uuid from qprofile_changes where kee = '" + qProfileChangeKee + "'")
.stream()
.map(row -> row.get("RULES_PROFILE_UUID"))
.findFirst())
.hasValue(expectedUuid);
}

private void insertQProfileChange(String kee, String rulesProfileUuid) {
db.executeInsert("qprofile_changes",
"kee", kee,
"change_type", Uuids.createFast(),
"rules_profile_uuid", rulesProfileUuid,
"created_at", System.currentTimeMillis());
}

private void insertRuleProfile(Long id, String uuid, String kee) {
db.executeInsert("rules_profiles",
"id", id,
"uuid", uuid,
"name", "name" + id,
"kee", kee,
"is_built_in", false);
}
}

+ 10
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest/schema.sql Datei anzeigen

@@ -0,0 +1,10 @@
CREATE TABLE "RULES_PROFILES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"UUID" VARCHAR(40) NOT NULL,
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"IS_BUILT_IN" BOOLEAN NOT NULL,
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
);

+ 12
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTableTest/schema.sql Datei anzeigen

@@ -0,0 +1,12 @@
CREATE TABLE "RULES_PROFILES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"KEE" VARCHAR(255) NOT NULL,
"IS_BUILT_IN" BOOLEAN NOT NULL,
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
);
ALTER TABLE "RULES_PROFILES" ADD CONSTRAINT "PK_RULES_PROFILES" PRIMARY KEY("ID");
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES"("KEE");

+ 11
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTableTest/schema.sql Datei anzeigen

@@ -0,0 +1,11 @@
CREATE TABLE "RULES_PROFILES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"UUID" VARCHAR(40) NOT NULL,
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"IS_BUILT_IN" BOOLEAN NOT NULL,
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
);
ALTER TABLE "RULES_PROFILES" ADD CONSTRAINT "PK_RULES_PROFILES" PRIMARY KEY("UUID");

+ 13
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTableTest/schema.sql Datei anzeigen

@@ -0,0 +1,13 @@
CREATE TABLE "RULES_PROFILES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"UUID" VARCHAR(40) NOT NULL,
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"KEE" VARCHAR(255) NOT NULL,
"IS_BUILT_IN" BOOLEAN NOT NULL,
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
);
ALTER TABLE "RULES_PROFILES" ADD CONSTRAINT "PK_RULES_PROFILES" PRIMARY KEY("ID");
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES"("KEE");

+ 11
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest/schema.sql Datei anzeigen

@@ -0,0 +1,11 @@
CREATE TABLE "RULES_PROFILES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"UUID" VARCHAR(40) NOT NULL,
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"IS_BUILT_IN" BOOLEAN NOT NULL,
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
);
ALTER TABLE "RULES_PROFILES" ADD CONSTRAINT "PK_RULES_PROFILES" PRIMARY KEY("ID");

+ 13
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest/schema.sql Datei anzeigen

@@ -0,0 +1,13 @@
CREATE TABLE "RULES_PROFILES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"UUID" VARCHAR(40) NOT NULL,
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"KEE" VARCHAR(255) NOT NULL,
"IS_BUILT_IN" BOOLEAN NOT NULL,
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
);
ALTER TABLE "RULES_PROFILES" ADD CONSTRAINT "PK_RULES_PROFILES" PRIMARY KEY("ID");
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES"("KEE");

+ 13
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullableTest/schema.sql Datei anzeigen

@@ -0,0 +1,13 @@
CREATE TABLE "RULES_PROFILES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"UUID" VARCHAR(40),
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"KEE" VARCHAR(255) NOT NULL,
"IS_BUILT_IN" BOOLEAN NOT NULL,
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
);
ALTER TABLE "RULES_PROFILES" ADD CONSTRAINT "PK_RULES_PROFILES" PRIMARY KEY("ID");
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES"("KEE");

+ 13
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuidTest/schema.sql Datei anzeigen

@@ -0,0 +1,13 @@
CREATE TABLE "RULES_PROFILES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"UUID" VARCHAR(40),
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"KEE" VARCHAR(255) NOT NULL,
"IS_BUILT_IN" BOOLEAN NOT NULL,
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
);
ALTER TABLE "RULES_PROFILES" ADD CONSTRAINT "PK_RULES_PROFILES" PRIMARY KEY("ID");
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES"("KEE");

+ 11
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTableTest/schema.sql Datei anzeigen

@@ -0,0 +1,11 @@
CREATE TABLE "ACTIVE_RULES"(
"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");

+ 11
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest/schema.sql Datei anzeigen

@@ -0,0 +1,11 @@
CREATE TABLE "ACTIVE_RULES"(
"UUID" VARCHAR(40) NOT NULL,
"PROFILE_ID" INTEGER NOT NULL,
"PROFILE_UUID" VARCHAR(40),
"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");

+ 12
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTableTest/schema.sql Datei anzeigen

@@ -0,0 +1,12 @@
CREATE TABLE "ACTIVE_RULES"(
"UUID" VARCHAR(40) NOT NULL,
"PROFILE_ID" INTEGER NOT NULL,
"PROFILE_UUID" VARCHAR(40) 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_UUID", "RULE_ID");

+ 12
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest/schema.sql Datei anzeigen

@@ -0,0 +1,12 @@
CREATE TABLE "ACTIVE_RULES"(
"UUID" VARCHAR(40) NOT NULL,
"PROFILE_ID" INTEGER NOT NULL,
"PROFILE_UUID" VARCHAR(40),
"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");

+ 26
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullableTest/schema.sql Datei anzeigen

@@ -0,0 +1,26 @@
CREATE TABLE "RULES_PROFILES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"UUID" VARCHAR(40) NOT NULL,
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"KEE" VARCHAR(255) NOT NULL,
"IS_BUILT_IN" BOOLEAN NOT NULL,
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
);
ALTER TABLE "RULES_PROFILES" ADD CONSTRAINT "PK_RULES_PROFILES" PRIMARY KEY("ID");
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES"("KEE");

CREATE TABLE "ACTIVE_RULES"(
"UUID" VARCHAR(40) NOT NULL,
"PROFILE_ID" INTEGER NOT NULL,
"PROFILE_UUID" VARCHAR(40),
"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");

+ 26
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuidTest/schema.sql Datei anzeigen

@@ -0,0 +1,26 @@
CREATE TABLE "RULES_PROFILES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"UUID" VARCHAR(40) NOT NULL,
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"KEE" VARCHAR(255) NOT NULL,
"IS_BUILT_IN" BOOLEAN NOT NULL,
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
);
ALTER TABLE "RULES_PROFILES" ADD CONSTRAINT "PK_RULES_PROFILES" PRIMARY KEY("ID");
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES"("KEE");

CREATE TABLE "ACTIVE_RULES"(
"UUID" VARCHAR(40) NOT NULL,
"PROFILE_ID" INTEGER NOT NULL,
"PROFILE_UUID" VARCHAR(40),
"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");

+ 28
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuidTest/schema.sql Datei anzeigen

@@ -0,0 +1,28 @@
CREATE TABLE "RULES_PROFILES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"UUID" VARCHAR(40) NOT NULL,
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"KEE" VARCHAR(255) NOT NULL,
"IS_BUILT_IN" BOOLEAN NOT NULL,
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
);
ALTER TABLE "RULES_PROFILES" ADD CONSTRAINT "PK_RULES_PROFILES" PRIMARY KEY("ID");
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES"("KEE");

CREATE TABLE "ORG_QPROFILES"(
"UUID" VARCHAR(255) NOT NULL,
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"RULES_PROFILE_UUID" VARCHAR(255) NOT NULL,
"PARENT_UUID" VARCHAR(255),
"LAST_USED" BIGINT,
"USER_UPDATED_AT" BIGINT,
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL
);
ALTER TABLE "ORG_QPROFILES" ADD CONSTRAINT "PK_ORG_QPROFILES" PRIMARY KEY("UUID");
CREATE INDEX "QPROFILES_ORG_UUID" ON "ORG_QPROFILES"("ORGANIZATION_UUID");
CREATE INDEX "QPROFILES_RP_UUID" ON "ORG_QPROFILES"("RULES_PROFILE_UUID");
CREATE INDEX "ORG_QPROFILES_PARENT_UUID" ON "ORG_QPROFILES"("PARENT_UUID");

+ 24
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuidTest/schema.sql Datei anzeigen

@@ -0,0 +1,24 @@
CREATE TABLE "RULES_PROFILES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"UUID" VARCHAR(40) NOT NULL,
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"KEE" VARCHAR(255) NOT NULL,
"IS_BUILT_IN" BOOLEAN NOT NULL,
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
);
ALTER TABLE "RULES_PROFILES" ADD CONSTRAINT "PK_RULES_PROFILES" PRIMARY KEY("ID");
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES"("KEE");

CREATE TABLE "QPROFILE_CHANGES"(
"KEE" VARCHAR(40) NOT NULL,
"RULES_PROFILE_UUID" VARCHAR(255) NOT NULL,
"CHANGE_TYPE" VARCHAR(20) NOT NULL,
"USER_UUID" VARCHAR(255),
"CHANGE_DATA" CLOB(2147483647),
"CREATED_AT" BIGINT NOT NULL
);
ALTER TABLE "QPROFILE_CHANGES" ADD CONSTRAINT "PK_QPROFILE_CHANGES" PRIMARY KEY("KEE");
CREATE INDEX "QP_CHANGES_RULES_PROFILE_UUID" ON "QPROFILE_CHANGES"("RULES_PROFILE_UUID");

+ 1
- 1
server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java Datei anzeigen

@@ -194,7 +194,7 @@ public class OrganizationUpdaterImpl implements OrganizationUpdater {
dbClient.qualityProfileDao().selectBuiltInRuleProfiles(dbSession).forEach(rulesProfile -> {
OrgQProfileDto dto = new OrgQProfileDto()
.setOrganizationUuid(organization.getUuid())
.setRulesProfileUuid(rulesProfile.getKee())
.setRulesProfileUuid(rulesProfile.getUuid())
.setUuid(uuidFactory.create());

QProfileName name = new QProfileName(rulesProfile.getLanguage(), rulesProfile.getName());

+ 3
- 3
server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java Datei anzeigen

@@ -104,7 +104,7 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
orgUuids.forEach(orgUuid -> {
OrgQProfileDto dto = new OrgQProfileDto()
.setOrganizationUuid(orgUuid)
.setRulesProfileUuid(rulesProfileDto.getKee())
.setRulesProfileUuid(rulesProfileDto.getUuid())
.setUuid(uuidFactory.create());

if (builtIn.isDefault() && orgUuidsWithoutDefault.contains(orgUuid)) {
@@ -130,7 +130,7 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {

private RulesProfileDto insertRulesProfile(DbSession dbSession, BuiltInQProfile builtIn, Date now) {
RulesProfileDto dto = new RulesProfileDto()
.setKee(uuidFactory.create())
.setUuid(uuidFactory.create())
.setName(builtIn.getName())
.setLanguage(builtIn.getLanguage())
.setIsBuiltIn(true)
@@ -145,7 +145,7 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
.orElseThrow(() -> new IllegalStateException("RuleDefinition not found for key " + ruleKey));

ActiveRuleDto dto = new ActiveRuleDto();
dto.setProfileId(rulesProfileDto.getId());
dto.setProfileUuid(rulesProfileDto.getUuid());
dto.setRuleId(ruleDefinitionDto.getId());
dto.setKey(ActiveRuleKey.of(rulesProfileDto, ruleDefinitionDto.getKey()));
dto.setSeverity(firstNonNull(activeRule.getSeverity(), ruleDefinitionDto.getSeverityString()));

+ 3
- 3
server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java Datei anzeigen

@@ -166,7 +166,7 @@ class RuleActivationContext {
* Whether the profile cursor is on the base profile or not.
*/
boolean isCascading() {
return currentRulesProfile != null && !currentRulesProfile.getKee().equals(baseRulesProfile.getKee());
return currentRulesProfile != null && !currentRulesProfile.getUuid().equals(baseRulesProfile.getUuid());
}

/**
@@ -193,7 +193,7 @@ class RuleActivationContext {
return;
}
Collection<QProfileDto> baseProfiles = profilesByUuid.values().stream()
.filter(p -> p.getRulesProfileUuid().equals(baseRulesProfile.getKee()))
.filter(p -> p.getRulesProfileUuid().equals(baseRulesProfile.getUuid()))
.collect(toArrayList(profilesByUuid.size()));
DescendantProfilesSupplier.Result result = descendantProfilesSupplier.get(baseProfiles, rulesById.keySet());
register(result.getProfiles());
@@ -228,7 +228,7 @@ class RuleActivationContext {
"%s rule %s cannot be activated on %s profile %s", currentRule.get().getLanguage(), ruleKey, ruleProfile.getLanguage(), ruleProfile.getName());
this.currentRulesProfile = ruleProfile;
this.currentProfiles = profilesByUuid.values().stream()
.filter(p -> p.getRulesProfileUuid().equals(ruleProfile.getKee()))
.filter(p -> p.getRulesProfileUuid().equals(ruleProfile.getUuid()))
.collect(Collectors.toList());
this.currentActiveRule = this.activeRulesByKey.get(ActiveRuleKey.of(ruleProfile, ruleKey));
this.currentParentActiveRule = this.currentProfiles.stream()

+ 3
- 3
server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java Datei anzeigen

@@ -246,7 +246,7 @@ public class RuleActivator {
RuleWrapper rule = context.getRule();

ActiveRuleDto activeRule = new ActiveRuleDto();
activeRule.setProfileId(context.getRulesProfile().getId());
activeRule.setProfileUuid(context.getRulesProfile().getUuid());
activeRule.setRuleId(rule.get().getId());
activeRule.setKey(ActiveRuleKey.of(context.getRulesProfile(), rule.get().getKey()));
String severity = change.getSeverity();
@@ -354,7 +354,7 @@ public class RuleActivator {
}

public RuleActivationContext createContextForBuiltInProfile(DbSession dbSession, RulesProfileDto builtInProfile, Collection<Integer> ruleIds) {
checkArgument(builtInProfile.isBuiltIn(), "Rules profile with UUID %s is not built-in", builtInProfile.getKee());
checkArgument(builtInProfile.isBuiltIn(), "Rules profile with UUID %s is not built-in", builtInProfile.getUuid());

RuleActivationContext.Builder builder = new RuleActivationContext.Builder();
builder.setDescendantProfilesSupplier(createDescendantProfilesSupplier(dbSession));
@@ -369,7 +369,7 @@ public class RuleActivator {

// load active rules
Collection<String> ruleProfileUuids = Stream
.concat(Stream.of(builtInProfile.getKee()), profiles.stream().map(QProfileDto::getRulesProfileUuid))
.concat(Stream.of(builtInProfile.getUuid()), profiles.stream().map(QProfileDto::getRulesProfileUuid))
.collect(MoreCollectors.toHashSet(profiles.size() + 1));
completeWithActiveRules(dbSession, builder, ruleIds, ruleProfileUuids);
return builder.build();

+ 1
- 1
server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java Datei anzeigen

@@ -236,7 +236,7 @@ public class OrganizationUpdaterImplTest {
private void insertRulesProfile(BuiltInQProfile builtIn) {
RulesProfileDto dto = new RulesProfileDto()
.setIsBuiltIn(true)
.setKee(RandomStringUtils.randomAlphabetic(40))
.setUuid(RandomStringUtils.randomAlphabetic(40))
.setLanguage(builtIn.getLanguage())
.setName(builtIn.getName());
dbClient.qualityProfileDao().insert(db.getSession(), dto);

+ 2
- 3
server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java Datei anzeigen

@@ -92,7 +92,6 @@ public class BuiltInQProfileInsertImplTest {
// same row in table rules_profiles is used
assertThat(profileOnOrg1.getKee()).isNotEqualTo(profileOnOrg2.getKee());
assertThat(profileOnOrg1.getRulesProfileUuid()).isEqualTo(profileOnOrg2.getRulesProfileUuid());
assertThat(profileOnOrg1.getId()).isEqualTo(profileOnOrg2.getId());
}

@Test
@@ -177,7 +176,7 @@ public class BuiltInQProfileInsertImplTest {
assertThat(activeRule.getInheritance()).isNull();
assertThat(activeRule.doesOverride()).isFalse();
assertThat(activeRule.getRuleId()).isEqualTo(rule.getId());
assertThat(activeRule.getProfileId()).isEqualTo(profile.getId());
assertThat(activeRule.getProfileUuid()).isEqualTo(profile.getRulesProfileUuid());
assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity);
assertThat(activeRule.getCreatedAt()).isPositive();
assertThat(activeRule.getUpdatedAt()).isPositive();
@@ -208,7 +207,7 @@ public class BuiltInQProfileInsertImplTest {
assertThat(profileOnOrg1.getUserUpdatedAt()).isNull();
assertThat(profileOnOrg1.getRulesUpdatedAt()).isNotEmpty();
assertThat(profileOnOrg1.getKee()).isNotEqualTo(profileOnOrg1.getRulesProfileUuid());
assertThat(profileOnOrg1.getId()).isNotNull();
assertThat(profileOnOrg1.getRulesProfileUuid()).isNotNull();
return profileOnOrg1;
}


+ 4
- 4
server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java Datei anzeigen

@@ -28,12 +28,12 @@ import org.assertj.core.groups.Tuple;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile;
import org.sonar.api.utils.System2;
import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.qualityprofile.ActiveRuleDto;
@@ -415,7 +415,7 @@ public class BuiltInQProfileUpdateImplTest {
private void assertThatProfileIsMarkedAsUpdated(RulesProfileDto dto) {
RulesProfileDto reloaded = db.getDbClient().qualityProfileDao().selectBuiltInRuleProfiles(db.getSession())
.stream()
.filter(p -> p.getKee().equals(dto.getKee()))
.filter(p -> p.getUuid().equals(dto.getUuid()))
.findFirst()
.get();
assertThat(reloaded.getRulesUpdatedAt()).isNotEmpty();
@@ -424,7 +424,7 @@ public class BuiltInQProfileUpdateImplTest {
private void assertThatProfileIsNotMarkedAsUpdated(RulesProfileDto dto) {
RulesProfileDto reloaded = db.getDbClient().qualityProfileDao().selectBuiltInRuleProfiles(db.getSession())
.stream()
.filter(p -> p.getKee().equals(dto.getKee()))
.filter(p -> p.getUuid().equals(dto.getUuid()))
.findFirst()
.get();
assertThat(reloaded.getRulesUpdatedAt()).isNull();
@@ -438,7 +438,7 @@ public class BuiltInQProfileUpdateImplTest {

private void activateRuleInDb(RulesProfileDto profile, RuleDefinitionDto rule, RulePriority severity) {
ActiveRuleDto dto = new ActiveRuleDto()
.setProfileId(profile.getId())
.setProfileUuid(profile.getUuid())
.setSeverity(severity.name())
.setRuleId(rule.getId())
.setCreatedAt(PAST)

+ 1
- 1
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java Datei anzeigen

@@ -50,7 +50,7 @@ public class QProfileResetImpl implements QProfileReset {

@Override
public BulkChangeResult reset(DbSession dbSession, QProfileDto profile, Collection<RuleActivation> activations) {
requireNonNull(profile.getId(), "Quality profile must be persisted");
requireNonNull(profile.getRulesProfileUuid(), "Quality profile must be persisted");
checkArgument(!profile.isBuiltIn(), "Operation forbidden for built-in Quality Profile '%s'", profile.getKee());

BulkChangeResult result = new BulkChangeResult();

+ 1
- 1
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java Datei anzeigen

@@ -170,7 +170,7 @@ public class RegisterQualityProfiles implements Startable {
return;
}

QProfileDto qualityProfile = dbClient.qualityProfileDao().selectByRuleProfileUuid(dbSession, qp.getOrganizationUuid(), rulesProfile.getKee());
QProfileDto qualityProfile = dbClient.qualityProfileDao().selectByRuleProfileUuid(dbSession, qp.getOrganizationUuid(), rulesProfile.getUuid());
if (qualityProfile == null) {
return;
}

+ 2
- 2
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java Datei anzeigen

@@ -117,7 +117,7 @@ public class ActiveRuleCompleter {
Rules.ActiveList.Builder activeRulesListResponse = Rules.ActiveList.newBuilder();
for (OrgActiveRuleDto activeRule : activeRules) {
activeRulesListResponse.addActiveList(buildActiveRuleResponse(activeRule, activeRuleParamsByActiveRuleKey.get(activeRule.getKey())));
profileUuids.add(activeRule.getProfileUuid());
profileUuids.add(activeRule.getOrgProfileUuid());
}
activesBuilder
.getMutableActives()
@@ -162,7 +162,7 @@ public class ActiveRuleCompleter {

private static Rules.Active buildActiveRuleResponse(OrgActiveRuleDto activeRule, List<ActiveRuleParamDto> parameters) {
Rules.Active.Builder builder = Rules.Active.newBuilder();
builder.setQProfile(activeRule.getProfileUuid());
builder.setQProfile(activeRule.getOrgProfileUuid());
String inheritance = activeRule.getInheritance();
builder.setInherit(inheritance != null ? inheritance : ActiveRuleInheritance.NONE.name());
builder.setSeverity(activeRule.getSeverityString());

+ 16
- 14
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java Datei anzeigen

@@ -89,7 +89,7 @@ public class QProfileFactoryImplTest {
assertThat(profile.getKee()).isNotEmpty();
assertThat(profile.getName()).isEqualTo("P1");
assertThat(profile.getLanguage()).isEqualTo("xoo");
assertThat(profile.getId()).isNotNull();
assertThat(profile.getRulesProfileUuid()).isNotNull();
assertThat(profile.isBuiltIn()).isFalse();

QProfileDto reloaded = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(dbSession, organization, profile.getName(), profile.getLanguage());
@@ -266,12 +266,12 @@ public class QProfileFactoryImplTest {
private RulesProfileDto createBuiltInProfile() {
RulesProfileDto rulesProfileDto = new RulesProfileDto()
.setIsBuiltIn(true)
.setKee(Uuids.createFast())
.setUuid(Uuids.createFast())
.setLanguage("xoo")
.setName("Sonar way");
db.getDbClient().qualityProfileDao().insert(dbSession, rulesProfileDto);
ActiveRuleDto activeRuleDto = new ActiveRuleDto()
.setProfileId(rulesProfileDto.getId())
.setProfileUuid(rulesProfileDto.getUuid())
.setRuleId(rule.getId())
.setSeverity(Severity.BLOCKER);
db.getDbClient().activeRuleDao().insert(dbSession, activeRuleDto);
@@ -284,7 +284,7 @@ public class QProfileFactoryImplTest {

db.getDbClient().qProfileChangeDao().insert(dbSession, new QProfileChangeDto()
.setChangeType(ActiveRuleChange.Type.ACTIVATED.name())
.setRulesProfileUuid(rulesProfileDto.getKee()));
.setRulesProfileUuid(rulesProfileDto.getUuid()));

db.commit();
return rulesProfileDto;
@@ -293,7 +293,7 @@ public class QProfileFactoryImplTest {
private QProfileDto associateBuiltInProfileToOrganization(RulesProfileDto rulesProfile, OrganizationDto organization) {
OrgQProfileDto orgQProfileDto = new OrgQProfileDto()
.setUuid(Uuids.createFast())
.setRulesProfileUuid(rulesProfile.getKee())
.setRulesProfileUuid(rulesProfile.getUuid())
.setOrganizationUuid(organization.getUuid());
db.getDbClient().qualityProfileDao().insert(dbSession, orgQProfileDto);
db.commit();
@@ -320,8 +320,8 @@ public class QProfileFactoryImplTest {

private void assertThatRulesProfileExists(RulesProfileDto rulesProfile) {
assertThat(db.getDbClient().qualityProfileDao().selectBuiltInRuleProfiles(dbSession))
.extracting(RulesProfileDto::getKee)
.containsExactly(rulesProfile.getKee());
.extracting(RulesProfileDto::getUuid)
.containsExactly(rulesProfile.getUuid());
assertThat(db.countRowsOfTable(dbSession, "active_rules")).isGreaterThan(0);
assertThat(db.countRowsOfTable(dbSession, "active_rule_parameters")).isGreaterThan(0);
assertThat(db.countRowsOfTable(dbSession, "qprofile_changes")).isGreaterThan(0);
@@ -331,18 +331,20 @@ public class QProfileFactoryImplTest {
assertThat(db.countSql(dbSession, "select count(*) from org_qprofiles where uuid = '" + profile.getKee() + "'")).isEqualTo(0);
assertThat(db.countSql(dbSession, "select count(*) from project_qprofiles where profile_key = '" + profile.getKee() + "'")).isEqualTo(0);
assertThat(db.countSql(dbSession, "select count(*) from default_qprofiles where qprofile_uuid = '" + profile.getKee() + "'")).isEqualTo(0);
assertThat(db.countSql(dbSession, "select count(*) from rules_profiles where kee = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(0);
assertThat(db.countSql(dbSession, "select count(*) from active_rules where profile_id = " + profile.getId())).isEqualTo(0);
assertThat(db.countSql(dbSession, "select count(*) from rules_profiles where uuid = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(0);
assertThat(db.countSql(dbSession, "select count(*) from active_rules where profile_uuid = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(0);
assertThat(db.countSql(dbSession, "select count(*) from qprofile_changes where rules_profile_uuid = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(0);
// TODO active_rule_parameters
}

private void assertThatCustomProfileExists(QProfileDto profile) {
assertThat(db.countSql(dbSession, "select count(*) from org_qprofiles where uuid = '" + profile.getKee() + "'")).isGreaterThan(0);
//assertThat(db.countSql(dbSession, "select count(*) from project_qprofiles where profile_key = '" + profile.getKee() + "'")).isGreaterThan(0);
//assertThat(db.countSql(dbSession, "select count(*) from default_qprofiles where qprofile_uuid = '" + profile.getKee() + "'")).isGreaterThan(0);
assertThat(db.countSql(dbSession, "select count(*) from rules_profiles where kee = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(1);
assertThat(db.countSql(dbSession, "select count(*) from active_rules where profile_id = " + profile.getId())).isGreaterThan(0);
// assertThat(db.countSql(dbSession, "select count(*) from project_qprofiles where profile_key = '" + profile.getKee() +
// "'")).isGreaterThan(0);
// assertThat(db.countSql(dbSession, "select count(*) from default_qprofiles where qprofile_uuid = '" + profile.getKee() +
// "'")).isGreaterThan(0);
assertThat(db.countSql(dbSession, "select count(*) from rules_profiles where uuid = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(1);
assertThat(db.countSql(dbSession, "select count(*) from active_rules where profile_uuid = '" + profile.getRulesProfileUuid() + "'")).isGreaterThan(0);
assertThat(db.countSql(dbSession, "select count(*) from qprofile_changes where rules_profile_uuid = '" + profile.getRulesProfileUuid() + "'")).isGreaterThan(0);
// TODO active_rule_parameters
}
@@ -352,7 +354,7 @@ public class QProfileFactoryImplTest {
assertThat(p2.getName()).isEqualTo(p1.getName());
assertThat(p2.getKee()).startsWith(p1.getKee());
assertThat(p2.getLanguage()).isEqualTo(p1.getLanguage());
assertThat(p2.getId()).isEqualTo(p1.getId());
assertThat(p2.getRulesProfileUuid()).isEqualTo(p1.getRulesProfileUuid());
assertThat(p2.getParentKee()).isEqualTo(p1.getParentKee());
}


+ 1
- 1
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java Datei anzeigen

@@ -111,7 +111,7 @@ public class QProfileResetImplTest {

@Test
public void fail_when_profile_is_not_persisted() {
QProfileDto profile = QualityProfileTesting.newQualityProfileDto().setLanguage(LANGUAGE);
QProfileDto profile = QualityProfileTesting.newQualityProfileDto().setRulesProfileUuid(null).setLanguage(LANGUAGE);
RuleDefinitionDto defaultRule = db.rules().insert(r -> r.setLanguage(LANGUAGE));

expectedException.expect(NullPointerException.class);

+ 1
- 1
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java Datei anzeigen

@@ -344,7 +344,7 @@ public class RegisterQualityProfilesNotificationTest {

private void activateRuleInDb(RulesProfileDto profile, RuleDefinitionDto rule, RulePriority severity) {
ActiveRuleDto dto = new ActiveRuleDto()
.setProfileId(profile.getId())
.setProfileUuid(profile.getUuid())
.setSeverity(severity.name())
.setRuleId(rule.getId())
.setCreatedAt(nextLong())

+ 2
- 2
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java Datei anzeigen

@@ -150,12 +150,12 @@ public class RegisterQualityProfilesTest {
.setIsBuiltIn(true)
.setLanguage(FOO_LANGUAGE.getKey())
.setOrganizationUuid(orgUuid)
.setRulesProfileUuid(ruleProfileWithoutRule.getKee());
.setRulesProfileUuid(ruleProfileWithoutRule.getUuid());
QProfileDto qProfileWithOneRule = newQualityProfileDto()
.setIsBuiltIn(true)
.setLanguage(FOO_LANGUAGE.getKey())
.setOrganizationUuid(orgUuid)
.setRulesProfileUuid(ruleProfileWithOneRule.getKee());
.setRulesProfileUuid(ruleProfileWithOneRule.getUuid());

db.qualityProfiles().insert(qProfileWithoutRule, qProfileWithOneRule);
db.qualityProfiles().setAsDefault(qProfileWithoutRule);

+ 1
- 1
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java Datei anzeigen

@@ -452,7 +452,7 @@ public class RuleUpdaterTest {

// Activate the custom rule
ActiveRuleDto activeRuleDto = new ActiveRuleDto()
.setProfileId(profileDto.getId())
.setProfileUuid(profileDto.getRulesProfileUuid())
.setRuleId(customRule.getId())
.setSeverity(Severity.BLOCKER);
db.getDbClient().activeRuleDao().insert(dbSession, activeRuleDto);

Laden…
Abbrechen
Speichern