From 94711e1ee7271e44e2061c3a2916ebb77aa4c956 Mon Sep 17 00:00:00 2001 From: Jacek Date: Fri, 24 Apr 2020 11:46:24 +0200 Subject: [PATCH] SONAR-13221 change PK to uuid of RULES_PROFILES table * change profile_id to profile_uuid for ACTIVE_RULES --- .../db/qualityprofile/ActiveRuleDao.java | 6 +- .../db/qualityprofile/ActiveRuleDto.java | 14 +- .../db/qualityprofile/ActiveRuleKey.java | 2 +- .../db/qualityprofile/OrgActiveRuleDto.java | 10 +- .../sonar/db/qualityprofile/QProfileDto.java | 13 +- .../db/qualityprofile/QualityProfileDao.java | 5 +- .../db/qualityprofile/RulesProfileDto.java | 29 +--- .../db/qualityprofile/ActiveRuleMapper.xml | 58 ++++---- .../qualityprofile/QProfileChangeMapper.xml | 4 +- .../QualityProfileExportMapper.xml | 4 +- .../qualityprofile/QualityProfileMapper.xml | 58 ++++---- server/sonar-db-dao/src/schema/schema-sq.ddl | 14 +- .../db/qualityprofile/ActiveRuleDaoTest.java | 20 +-- .../qualityprofile/QualityProfileDaoTest.java | 22 ++- .../qualityprofile/QualityProfileTesting.java | 2 +- .../db/migration/version/v83/DbVersion83.java | 44 ++++++ ...ryKeyOnUuidColumnOfRulesProfilesTable.java | 38 +++++ .../AddUuidColumnToRulesProfilesTable.java | 31 ++++ .../DropIdColumnOfRulesProfilesTable.java | 33 +++++ .../DropKeeColumnOfRulesProfilesTable.java | 41 ++++++ ...maryKeyOnIdColumnOfRulesProfilesTable.java | 32 ++++ ...eIndexOnKeeColumnOfRulesProfilesTable.java | 52 +++++++ ...akeRulesProfilesUuidColumnNotNullable.java | 32 ++++ .../PopulateRulesProfilesUuid.java | 50 +++++++ ...ddProfileUuidColumnToActiveRulesTable.java | 50 +++++++ ...OnProfileUuidColumnOfActiveRulesTable.java | 67 +++++++++ ...DropProfileIdColumnOfActiveRulesTable.java | 41 ++++++ ...exOnProfileIdColumnOfActiveRulesTable.java | 52 +++++++ ...tiveRulesProfileUuidColumnNotNullable.java | 50 +++++++ .../PopulateActiveRulesProfileUuid.java | 49 +++++++ .../PopulateOrgQProfilesRulesProfileUuid.java | 48 ++++++ ...pulateQProfileChangesRulesProfileUuid.java | 48 ++++++ ...yOnUuidColumnOfRulesProfilesTableTest.java | 49 +++++++ ...AddUuidColumnToRulesProfilesTableTest.java | 67 +++++++++ .../DropIdColumnOfRulesProfilesTableTest.java | 49 +++++++ ...DropKeeColumnOfRulesProfilesTableTest.java | 49 +++++++ ...KeyOnIdColumnOfRulesProfilesTableTest.java | 54 +++++++ ...exOnKeeColumnOfRulesProfilesTableTest.java | 54 +++++++ ...ulesProfilesUuidColumnNotNullableTest.java | 43 ++++++ .../PopulateRulesProfilesUuidTest.java | 81 +++++++++++ ...ofileUuidColumnToActiveRulesTableTest.java | 63 ++++++++ ...ofileUuidColumnOfActiveRulesTableTest.java | 51 +++++++ ...ProfileIdColumnOfActiveRulesTableTest.java | 49 +++++++ ...ProfileIdColumnOfActiveRulesTableTest.java | 51 +++++++ ...RulesProfileUuidColumnNotNullableTest.java | 43 ++++++ .../PopulateActiveRulesProfileUuidTest.java | 113 +++++++++++++++ ...ulateOrgQProfilesRulesProfileUuidTest.java | 137 ++++++++++++++++++ ...teQProfileChangesRulesProfileUuidTest.java | 136 +++++++++++++++++ .../schema.sql | 10 ++ .../schema.sql | 12 ++ .../schema.sql | 11 ++ .../schema.sql | 13 ++ .../schema.sql | 11 ++ .../schema.sql | 13 ++ .../schema.sql | 13 ++ .../PopulateRulesProfilesUuidTest/schema.sql | 13 ++ .../schema.sql | 11 ++ .../schema.sql | 11 ++ .../schema.sql | 12 ++ .../schema.sql | 12 ++ .../schema.sql | 26 ++++ .../schema.sql | 26 ++++ .../schema.sql | 28 ++++ .../schema.sql | 24 +++ .../organization/OrganizationUpdaterImpl.java | 2 +- .../BuiltInQProfileInsertImpl.java | 6 +- .../qualityprofile/RuleActivationContext.java | 6 +- .../server/qualityprofile/RuleActivator.java | 6 +- .../OrganizationUpdaterImplTest.java | 2 +- .../BuiltInQProfileInsertImplTest.java | 5 +- .../BuiltInQProfileUpdateImplTest.java | 8 +- .../qualityprofile/QProfileResetImpl.java | 2 +- .../RegisterQualityProfiles.java | 2 +- .../server/rule/ws/ActiveRuleCompleter.java | 4 +- .../QProfileFactoryImplTest.java | 30 ++-- .../qualityprofile/QProfileResetImplTest.java | 2 +- ...gisterQualityProfilesNotificationTest.java | 2 +- .../RegisterQualityProfilesTest.java | 4 +- .../sonar/server/rule/RuleUpdaterTest.java | 2 +- 79 files changed, 2248 insertions(+), 189 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuid.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuid.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuid.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuid.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuidTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuidTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuidTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuidTest.java create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuidTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuidTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuidTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuidTest/schema.sql diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java index bea2f1a725a..a5ef41393fe 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java @@ -86,7 +86,7 @@ public class ActiveRuleDao implements Dao { } public List selectByRuleProfile(DbSession dbSession, RulesProfileDto ruleProfileDto) { - return mapper(dbSession).selectByRuleProfileUuid(ruleProfileDto.getKee()); + return mapper(dbSession).selectByRuleProfileUuid(ruleProfileDto.getUuid()); } public Collection selectByRulesAndRuleProfileUuids(DbSession dbSession, Collection ruleIds, Collection 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); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java index 6cc8c2efb22..21426eea525 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java @@ -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; diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleKey.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleKey.java index ad47324cdf4..ce16fb53fbe 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleKey.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleKey.java @@ -45,7 +45,7 @@ public class ActiveRuleKey implements Serializable, Comparable { } public static ActiveRuleKey of(RulesProfileDto rulesProfile, RuleKey ruleKey) { - return new ActiveRuleKey(rulesProfile.getKee(), ruleKey); + return new ActiveRuleKey(rulesProfile.getUuid(), ruleKey); } /** diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/OrgActiveRuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/OrgActiveRuleDto.java index 25d428d10b4..59aacb3335a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/OrgActiveRuleDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/OrgActiveRuleDto.java @@ -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; } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java index 462023295d2..ff041a371f8 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java @@ -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()) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java index af0525ae5d4..1c7c77b3e3b 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java @@ -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 selectQProfilesByRuleProfile(DbSession dbSession, RulesProfileDto rulesProfile) { - return mapper(dbSession).selectQProfilesByRuleProfileUuid(rulesProfile.getKee()); + return mapper(dbSession).selectQProfilesByRuleProfileUuid(rulesProfile.getUuid()); } private static String sqlQueryString(@Nullable String query) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java index ad26e66cfda..415532e0a58 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java @@ -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()); } } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml index 26e013c0bfb..c40c83c6e51 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml @@ -5,42 +5,42 @@ 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" 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" - 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 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 #{rulesProfileUuid, jdbcType=VARCHAR} ) @@ -97,7 +97,7 @@ from active_rules a 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} @@ -109,7 +109,7 @@ where - (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 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} @@ -130,8 +130,8 @@ select 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 #{type, jdbcType=INTEGER} @@ -144,7 +144,7 @@ from active_rules a where - rp.kee = #{ruleProfileUuid, jdbcType=VARCHAR} + rp.uuid = #{ruleProfileUuid, jdbcType=VARCHAR} 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 oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} @@ -311,7 +311,7 @@ @@ -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 diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileChangeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileChangeMapper.xml index 53b284f6374..234fc6529fa 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileChangeMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileChangeMapper.xml @@ -66,8 +66,8 @@ 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} diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml index 18f2256dfe6..36fdc79bec6 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml @@ -28,8 +28,8 @@ select 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 diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml index 1bd105d38cc..2afa6e164fd 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml @@ -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 @@ - 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 - + 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} @@ -103,7 +101,7 @@ delete from rules_profiles - where kee in + where uuid in #{uuid, jdbcType=VARCHAR} @@ -122,14 +120,14 @@ @@ -168,7 +166,7 @@ select 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 #{language, jdbcType=VARCHAR} @@ -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 <> 'REMOVED' - WHERE profile_id=rp.id + WHERE profile_uuid=rp.uuid ) @@ -192,7 +190,7 @@ select 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 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} @@ -213,7 +211,7 @@ select 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 #{language, jdbcType=VARCHAR} @@ -224,7 +222,7 @@ select 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} @@ -233,7 +231,7 @@ select 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 #{uuid, jdbcType=VARCHAR} @@ -242,7 +240,7 @@ select 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 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} diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index e30a39e2ce3..3df56d3fc64 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -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, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java index 738d46df976..bd561b4f3f5 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java @@ -147,8 +147,8 @@ public class ActiveRuleDaoTest { List 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 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 diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java index f8cf46c71d8..a8f3ecaba0b 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java @@ -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> uuids = db.select(dbSession, "select kee as \"uuid\" from rules_profiles"); + List> 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 result = db.getDbClient().qualityProfileDao().selectQProfilesByRuleProfile(db.getSession(), new RulesProfileDto().setKee("unknown")); + List result = db.getDbClient().qualityProfileDao().selectQProfilesByRuleProfile(db.getSession(), new RulesProfileDto().setUuid("unknown")); assertThat(result).isEmpty(); } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileTesting.java index 80299a723af..2df3eef2984 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileTesting.java @@ -65,7 +65,7 @@ public class QualityProfileTesting { */ public static RulesProfileDto newRuleProfileDto(Consumer... populators) { RulesProfileDto dto = new RulesProfileDto() - .setKee("uuid" + randomAlphabetic(10)) + .setUuid("uuid" + randomAlphabetic(10)) .setName("name" + randomAlphabetic(10)) .setLanguage("lang" + randomAlphabetic(5)) .setIsBuiltIn(false); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java index fc00529532d..b8f50ffbba7 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java @@ -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) + ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTable.java new file mode 100644 index 00000000000..ac78aa9d950 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTable.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTable.java new file mode 100644 index 00000000000..4a4ae6c1714 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTable.java @@ -0,0 +1,31 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTable.java new file mode 100644 index 00000000000..68c19acb3e1 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTable.java @@ -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); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTable.java new file mode 100644 index 00000000000..f630221d84d --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTable.java @@ -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()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTable.java new file mode 100644 index 00000000000..2faecfe8873 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTable.java @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTable.java new file mode 100644 index 00000000000..560e6c01db1 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTable.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullable.java new file mode 100644 index 00000000000..6d13a0803e9 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullable.java @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuid.java new file mode 100644 index 00000000000..51975861f05 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuid.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTable.java new file mode 100644 index 00000000000..ec3847e8621 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTable.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable.java new file mode 100644 index 00000000000..baf6dfe2f41 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable.java @@ -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); + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTable.java new file mode 100644 index 00000000000..c541b62c6f9 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTable.java @@ -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()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTable.java new file mode 100644 index 00000000000..7e0c9d6a2cd --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTable.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullable.java new file mode 100644 index 00000000000..4e65662aed8 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullable.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuid.java new file mode 100644 index 00000000000..2dc9aa6644d --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuid.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuid.java new file mode 100644 index 00000000000..7786b6e30e5 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuid.java @@ -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; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuid.java new file mode 100644 index 00000000000..0d7cb591b64 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuid.java @@ -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; + }); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest.java new file mode 100644 index 00000000000..9afa60ff498 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTableTest.java new file mode 100644 index 00000000000..3dca0a58d25 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTableTest.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTableTest.java new file mode 100644 index 00000000000..c356f3f0712 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTableTest.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTableTest.java new file mode 100644 index 00000000000..fce041d784a --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTableTest.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.java new file mode 100644 index 00000000000..99724f345d0 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest.java new file mode 100644 index 00000000000..92452543714 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullableTest.java new file mode 100644 index 00000000000..7e6339c43ee --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullableTest.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuidTest.java new file mode 100644 index 00000000000..db6851c9cfc --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuidTest.java @@ -0,0 +1,81 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTableTest.java new file mode 100644 index 00000000000..a794fc06ccb --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTableTest.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest.java new file mode 100644 index 00000000000..4801d8cefa4 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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"); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTableTest.java new file mode 100644 index 00000000000..f48b46d8d40 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTableTest.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest.java new file mode 100644 index 00000000000..5524bd2fbd7 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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"); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullableTest.java new file mode 100644 index 00000000000..33c92e91960 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullableTest.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuidTest.java new file mode 100644 index 00000000000..cb5527ccbd5 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuidTest.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuidTest.java new file mode 100644 index 00000000000..238dcf5a012 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuidTest.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuidTest.java new file mode 100644 index 00000000000..ac4936ea4ed --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuidTest.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest/schema.sql new file mode 100644 index 00000000000..8f7a7f216ae --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTableTest/schema.sql @@ -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 +); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTableTest/schema.sql new file mode 100644 index 00000000000..de92d69aeb0 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/AddUuidColumnToRulesProfilesTableTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTableTest/schema.sql new file mode 100644 index 00000000000..0236b7e6554 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropIdColumnOfRulesProfilesTableTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTableTest/schema.sql new file mode 100644 index 00000000000..eeb2ebcbd94 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropKeeColumnOfRulesProfilesTableTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest/schema.sql new file mode 100644 index 00000000000..20448a4d9fe --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest/schema.sql new file mode 100644 index 00000000000..eeb2ebcbd94 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTableTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullableTest/schema.sql new file mode 100644 index 00000000000..fd1ad1ea6a2 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/MakeRulesProfilesUuidColumnNotNullableTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuidTest/schema.sql new file mode 100644 index 00000000000..fd1ad1ea6a2 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/PopulateRulesProfilesUuidTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTableTest/schema.sql new file mode 100644 index 00000000000..d2e7c11c080 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddProfileUuidColumnToActiveRulesTableTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest/schema.sql new file mode 100644 index 00000000000..2dedcc6b5e2 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTableTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTableTest/schema.sql new file mode 100644 index 00000000000..2adacc4076d --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropProfileIdColumnOfActiveRulesTableTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest/schema.sql new file mode 100644 index 00000000000..d7d0db7aa73 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTableTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullableTest/schema.sql new file mode 100644 index 00000000000..161696a041f --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/MakeActiveRulesProfileUuidColumnNotNullableTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuidTest/schema.sql new file mode 100644 index 00000000000..161696a041f --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/activerules/PopulateActiveRulesProfileUuidTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuidTest/schema.sql new file mode 100644 index 00000000000..a1781cb90cc --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/orgqprofiles/PopulateOrgQProfilesRulesProfileUuidTest/schema.sql @@ -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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuidTest/schema.sql new file mode 100644 index 00000000000..75148b62b24 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rulesprofiles/fk/qprofilechanges/PopulateQProfileChangesRulesProfileUuidTest/schema.sql @@ -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"); diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java index 7f6e27efb88..beb8569be39 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java @@ -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()); diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java index 8b35dbe25c5..3f5cc01fd2a 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java @@ -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())); diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java index 8cc18f2713b..9cc440cd51b 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java @@ -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 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() diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java index 1d8b6ab8196..be862460f9e 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java @@ -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 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 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(); diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java index 2395ce8b267..bcf48f97ca8 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java @@ -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); diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java index e88ed59fc79..91a99f264c1 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java @@ -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; } diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java index ec503feab87..c4184597696 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java @@ -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) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java index cd513b3766a..83b9f3cc2a0 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java @@ -50,7 +50,7 @@ public class QProfileResetImpl implements QProfileReset { @Override public BulkChangeResult reset(DbSession dbSession, QProfileDto profile, Collection 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(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java index 1a4aa5b10a2..c5e9b8bf8d1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java @@ -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; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java index 3a17472127b..3e73b991842 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java @@ -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 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()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java index f365dadb1bb..6239bbcf78d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java @@ -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()); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java index 67d6e3160c1..50cc76d3619 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java @@ -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); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java index 628a3b1f811..82789a370e6 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java @@ -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()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java index be8cc329324..6292b61fce3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java @@ -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); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java index adc22dd84b2..74915655c0e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java @@ -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); -- 2.39.5