aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java18
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java12
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/PrIssueDto.java12
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java3
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java3
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml5
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml1
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml1
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml1
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl5
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDtoTest.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java2
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java8
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DropProjectBranchesKeyType.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/FillProjectBranchesBranchType.java46
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectBranchesBranchTypeNotNullable.java (renamed from server/sonar-db-dao/src/main/java/org/sonar/db/component/KeyType.java)25
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/DropProjectBranchesKeyTypeTest.java66
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/FillProjectBranchesBranchTypeTest.java70
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectBranchesBranchTypeNotNullableTest.java65
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/DropProjectBranchesKeyTypeTest/schema.sql16
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/FillProjectBranchesBranchTypeTest/schema.sql16
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeProjectBranchesBranchTypeNotNullableTest/schema.sql16
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ListAction.java2
28 files changed, 393 insertions, 63 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java
index 68bd4404074..21aaed78c35 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java
@@ -31,8 +31,8 @@ import org.sonar.ce.task.projectanalysis.component.SiblingComponentsWithOpenIssu
import org.sonar.core.issue.DefaultIssue;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.KeyType;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.issue.PrIssueDto;
@@ -69,7 +69,7 @@ public class SiblingsIssuesLoader {
}
private static SiblingIssue toSiblingIssue(PrIssueDto dto) {
- Preconditions.checkState(dto.getKeyType().equals(KeyType.PULL_REQUEST), "Expected all issues to belong to P/Rs");
+ Preconditions.checkState(dto.getBranchType().equals(BranchType.PULL_REQUEST), "Expected all issues to belong to P/Rs");
return new SiblingIssue(dto.getKey(), dto.getLine(), dto.getMessage(), dto.getChecksum(), dto.getRuleKey(), dto.getStatus(), dto.getBranchKey(),
longToDate(dto.getIssueUpdateDate()));
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java
index 0898737cec8..eea97147e49 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java
@@ -41,27 +41,17 @@ public class BranchDao implements Dao {
}
public void insert(DbSession dbSession, BranchDto dto) {
- setKeyType(dto);
mapper(dbSession).insert(dto, system2.now());
}
public void upsert(DbSession dbSession, BranchDto dto) {
BranchMapper mapper = mapper(dbSession);
long now = system2.now();
- setKeyType(dto);
if (mapper.update(dto, now) == 0) {
mapper.insert(dto, now);
}
}
- private static void setKeyType(BranchDto dto) {
- if (dto.getBranchType() == BranchType.PULL_REQUEST) {
- dto.setKeyType(KeyType.PULL_REQUEST);
- } else {
- dto.setKeyType(KeyType.BRANCH);
- }
- }
-
public int updateMainBranchName(DbSession dbSession, String projectUuid, String newBranchKey) {
long now = system2.now();
return mapper(dbSession).updateMainBranchName(projectUuid, newBranchKey, now);
@@ -73,7 +63,7 @@ public class BranchDao implements Dao {
}
public Optional<BranchDto> selectByBranchKey(DbSession dbSession, String projectUuid, String key) {
- return selectByKey(dbSession, projectUuid, key, KeyType.BRANCH);
+ return selectByKey(dbSession, projectUuid, key, BranchType.BRANCH);
}
public List<BranchDto> selectByBranchKeys(DbSession dbSession, Map<String, String> branchKeyByProjectUuid) {
@@ -84,11 +74,11 @@ public class BranchDao implements Dao {
}
public Optional<BranchDto> selectByPullRequestKey(DbSession dbSession, String projectUuid, String key) {
- return selectByKey(dbSession, projectUuid, key, KeyType.PULL_REQUEST);
+ return selectByKey(dbSession, projectUuid, key, BranchType.PULL_REQUEST);
}
- private static Optional<BranchDto> selectByKey(DbSession dbSession, String projectUuid, String key, KeyType keyType) {
- return Optional.ofNullable(mapper(dbSession).selectByKey(projectUuid, key, keyType));
+ private static Optional<BranchDto> selectByKey(DbSession dbSession, String projectUuid, String key, BranchType branchType) {
+ return Optional.ofNullable(mapper(dbSession).selectByKey(projectUuid, key, branchType));
}
public Collection<BranchDto> selectByComponent(DbSession dbSession, ComponentDto component) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java
index cfdb4dfbdac..72a6952333d 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java
@@ -61,12 +61,6 @@ public class BranchDto {
private String kee;
/**
- * Key type, as provided by {@link KeyType}.
- * Not null.
- */
- private KeyType keyType;
-
- /**
* Branch type, as provided by {@link BranchType}.
* Not null.
*/
@@ -138,11 +132,6 @@ public class BranchDto {
return this;
}
- BranchDto setKeyType(KeyType keyType) {
- this.keyType = keyType;
- return this;
- }
-
public BranchType getBranchType() {
return branchType;
}
@@ -239,7 +228,6 @@ public class BranchDto {
"uuid='" + uuid + '\'' +
", projectUuid='" + projectUuid + '\'' +
", kee='" + kee + '\'' +
- ", keyType=" + keyType +
", branchType=" + branchType +
", mergeBranchUuid='" + mergeBranchUuid + '\'' +
", excludeFromPurge=" + excludeFromPurge +
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java
index 60a017fcac3..c44507015fd 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java
@@ -38,7 +38,7 @@ public interface BranchMapper {
int updateExcludeFromPurge(@Param("uuid") String uuid, @Param("excludeFromPurge") boolean excludeFromPurge,
@Param("now") long now);
- BranchDto selectByKey(@Param("projectUuid") String projectUuid, @Param("key") String key, @Param("keyType") KeyType keyType);
+ BranchDto selectByKey(@Param("projectUuid") String projectUuid, @Param("key") String key, @Param("branchType") BranchType branchType);
BranchDto selectByUuid(@Param("uuid") String uuid);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/PrIssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/PrIssueDto.java
index ccf39fba9fc..94a2653fa8c 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/PrIssueDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/PrIssueDto.java
@@ -25,7 +25,7 @@ import javax.annotation.Nullable;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.rule.RuleKey;
-import org.sonar.db.component.KeyType;
+import org.sonar.db.component.BranchType;
public final class PrIssueDto implements Serializable {
@@ -40,7 +40,7 @@ public final class PrIssueDto implements Serializable {
private String ruleKey;
private String ruleRepo;
private String branchKey;
- private KeyType keyType;
+ private BranchType branchType;
public String getKey() {
return kee;
@@ -83,12 +83,12 @@ public final class PrIssueDto implements Serializable {
return this;
}
- public KeyType getKeyType() {
- return keyType;
+ public BranchType getBranchType() {
+ return branchType;
}
- public PrIssueDto setKeyType(KeyType s) {
- this.keyType = s;
+ public PrIssueDto setBranchType(BranchType s) {
+ this.branchType = s;
return this;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java
index 4b778ff52d0..d4abbce6721 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java
@@ -30,7 +30,6 @@ import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.KeyType;
import org.sonar.db.dialect.Dialect;
import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
@@ -101,7 +100,7 @@ public class LiveMeasureDao implements Dao {
*/
public long sumNclocOfBiggestBranch(DbSession dbSession, SumNclocDbQuery dbQuery) {
Long ncloc = mapper(dbSession).sumNclocOfBiggestBranch(
- NCLOC_KEY, KeyType.BRANCH, BranchType.BRANCH, dbQuery.getOrganizationUuid(), dbQuery.getOnlyPrivateProjects(), dbQuery.getProjectUuidToExclude());
+ NCLOC_KEY, BranchType.BRANCH, dbQuery.getOrganizationUuid(), dbQuery.getOnlyPrivateProjects(), dbQuery.getProjectUuidToExclude());
return ncloc == null ? 0L : ncloc;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java
index 5f805a36979..22e5ee92cc1 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java
@@ -25,7 +25,6 @@ import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.ResultHandler;
import org.sonar.db.component.BranchType;
-import org.sonar.db.component.KeyType;
public interface LiveMeasureMapper {
@@ -58,7 +57,6 @@ public interface LiveMeasureMapper {
Long sumNclocOfBiggestBranch(
@Param("ncloc") String nclocKey,
- @Param("branch") KeyType branchOrPullRequest,
@Param("branchType") BranchType branchType,
@Param("organizationUuid") String organizationUuid,
@Param("private") Boolean privateProject,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java
index b81990c3ea2..f120445e3bf 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java
@@ -29,7 +29,6 @@ import org.sonar.db.DbSession;
import org.sonar.db.Pagination;
import org.sonar.db.alm.ALM;
import org.sonar.db.component.BranchType;
-import org.sonar.db.component.KeyType;
import org.sonar.db.qualitygate.QGateWithOrgDto;
import org.sonar.db.user.GroupDto;
@@ -145,7 +144,7 @@ public class OrganizationDao implements Dao {
public List<OrganizationWithNclocDto> selectOrganizationsWithNcloc(DbSession dbSession, List<String> organizationUuids) {
List<OrganizationWithNclocDto> result = new ArrayList<>();
executeLargeUpdates(organizationUuids, chunk ->
- result.addAll(getMapper(dbSession).selectOrganizationsWithNcloc(NCLOC_KEY, chunk, KeyType.BRANCH, BranchType.BRANCH))
+ result.addAll(getMapper(dbSession).selectOrganizationsWithNcloc(NCLOC_KEY, chunk, BranchType.BRANCH))
);
return result;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java
index fdf43b88c0b..8e806bda37b 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java
@@ -24,7 +24,6 @@ import javax.annotation.CheckForNull;
import org.apache.ibatis.annotations.Param;
import org.sonar.db.Pagination;
import org.sonar.db.component.BranchType;
-import org.sonar.db.component.KeyType;
public interface OrganizationMapper {
void insert(@Param("organization") OrganizationDto organization, @Param("newProjectPrivate") boolean newProjectPrivate);
@@ -80,7 +79,6 @@ public interface OrganizationMapper {
List<OrganizationWithNclocDto> selectOrganizationsWithNcloc(
@Param("ncloc") String ncloc,
@Param("organizationUuids") List<String> organizationUuids,
- @Param("branch") KeyType branchOrPullRequest,
@Param("branchType") BranchType branchType);
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml
index af4785fd8d9..dccb832be36 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml
@@ -6,7 +6,6 @@
pb.uuid as uuid,
pb.project_uuid as projectUuid,
pb.kee as kee,
- pb.key_type as keyType,
pb.branch_type as branchType,
pb.merge_branch_uuid as mergeBranchUuid,
pb.pull_request_binary as pullRequestBinary,
@@ -19,7 +18,6 @@
uuid,
project_uuid,
kee,
- key_type,
branch_type,
merge_branch_uuid,
pull_request_binary,
@@ -31,7 +29,6 @@
#{dto.uuid, jdbcType=VARCHAR},
#{dto.projectUuid, jdbcType=VARCHAR},
#{dto.kee, jdbcType=VARCHAR},
- #{dto.keyType, jdbcType=VARCHAR},
#{dto.branchType, jdbcType=VARCHAR},
#{dto.mergeBranchUuid, jdbcType=VARCHAR},
#{dto.pullRequestBinary, jdbcType=BINARY},
@@ -76,7 +73,7 @@
where
pb.project_uuid = #{projectUuid, jdbcType=VARCHAR} and
pb.kee = #{key, jdbcType=VARCHAR} and
- pb.key_type = #{keyType, jdbcType=VARCHAR}
+ pb.branch_type = #{branchType, jdbcType=VARCHAR}
</select>
<select id="selectByBranchKeys" resultType="org.sonar.db.component.BranchDto">
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index 89de3576586..d3a1d7ae509 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -728,7 +728,6 @@
inner join components p on b.project_uuid = p.uuid
where
m.name = 'ncloc'
- and b.key_type = 'BRANCH'
and b.branch_type = 'BRANCH'
and p.enabled = ${_true}
and p.private = ${_true}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
index 5dc62303552..2056461e95a 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
@@ -296,7 +296,7 @@
r.plugin_rule_key as ruleKey,
r.plugin_name as ruleRepo,
b.kee as branchKey,
- b.key_type as keyType
+ b.branch_type as branchType
from issues i
inner join rules r on r.uuid = i.rule_uuid
inner join project_branches b on i.project_uuid = b.uuid
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
index b04fccfefca..499640bead1 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
@@ -68,7 +68,6 @@
and p.copy_component_uuid is null
and p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
and b.branch_type = #{branchType, jdbcType=VARCHAR}
- and b.key_type = #{branch, jdbcType=VARCHAR}
<if test="projectUuidToExclude != null">
and b.project_uuid &lt;&gt; #{projectUuidToExclude,jdbcType=VARCHAR}
</if>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
index b7d9744bf94..449b2b73bc5 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
@@ -203,7 +203,6 @@
and p.copy_component_uuid is null
and p.organization_uuid in <foreach collection="organizationUuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
and b.branch_type = #{branchType, jdbcType=VARCHAR}
- and b.key_type = #{branch, jdbcType=VARCHAR}
group by b.project_uuid, p.organization_uuid
) sumncloc
group by orgUuid
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index e4f53071172..ae5bb2b7ca8 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -629,9 +629,8 @@ CREATE TABLE "PROJECT_BRANCHES"(
"UUID" VARCHAR(50) NOT NULL,
"PROJECT_UUID" VARCHAR(50) NOT NULL,
"KEE" VARCHAR(255) NOT NULL,
- "BRANCH_TYPE" VARCHAR(12),
+ "BRANCH_TYPE" VARCHAR(12) NOT NULL,
"MERGE_BRANCH_UUID" VARCHAR(50),
- "KEY_TYPE" VARCHAR(12) NOT NULL,
"PULL_REQUEST_BINARY" BLOB,
"MANUAL_BASELINE_ANALYSIS_UUID" VARCHAR(40),
"CREATED_AT" BIGINT NOT NULL,
@@ -640,7 +639,7 @@ CREATE TABLE "PROJECT_BRANCHES"(
"NEED_ISSUE_SYNC" BOOLEAN NOT NULL
);
ALTER TABLE "PROJECT_BRANCHES" ADD CONSTRAINT "PK_PROJECT_BRANCHES" PRIMARY KEY("UUID");
-CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE_KEY_TYPE" ON "PROJECT_BRANCHES"("PROJECT_UUID", "KEE", "KEY_TYPE");
+CREATE UNIQUE INDEX "UNIQ_PROJECT_BRANCHES" ON "PROJECT_BRANCHES"("BRANCH_TYPE", "PROJECT_UUID", "KEE");
CREATE TABLE "PROJECT_LINKS"(
"UUID" VARCHAR(40) NOT NULL,
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDtoTest.java
index 48a786bde79..feda89a2963 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDtoTest.java
@@ -59,7 +59,7 @@ public class BranchDtoTest {
underTest.setExcludeFromPurge(true);
assertThat(underTest.toString()).isEqualTo("BranchDto{uuid='U1', " +
- "projectUuid='U2', kee='K1', keyType=null, branchType=BRANCH, mergeBranchUuid='U3', excludeFromPurge=true, needIssueSync=false}");
+ "projectUuid='U2', kee='K1', branchType=BRANCH, mergeBranchUuid='U3', excludeFromPurge=true, needIssueSync=false}");
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
index 1621814abab..6813a473440 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
@@ -37,7 +37,6 @@ import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.ComponentUpdateDto;
-import org.sonar.db.component.KeyType;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
@@ -237,7 +236,6 @@ public class IssueDaoTest {
assertThat(fp.getRuleKey()).isNotNull();
assertThat(fp.getStatus()).isNotNull();
assertThat(fp.getBranchKey()).isEqualTo("feature/foo");
- assertThat(fp.getKeyType()).isEqualTo(KeyType.BRANCH);
assertThat(fp.getIssueUpdateDate()).isNotNull();
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java
index 0396ecac844..daeb281ea00 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java
@@ -51,7 +51,11 @@ public class DbVersion85 implements DbVersion {
.add(4020, "Populate 'message_type' column of 'ce_task_message' table", PopulateMessageTypeColumnOfCeTaskMessageTable.class)
.add(4021, "Make 'message_type' column not nullable for `ce_task_message` table", MakeMessageTypeColumnNotNullableOnCeTaskMessageTable.class)
.add(4022, "Add index on 'message_type' column of `ce_task_message` table", AddIndexOnMessageTypeColumnOfCeTaskMessageTable.class)
- .add(4023, "Create 'user_dismissed_messages' table", CreateUserDismissedMessagesTable.class
- );
+ .add(4023, "Create 'user_dismissed_messages' table", CreateUserDismissedMessagesTable.class)
+ .add(4024, "Populate 'branch_type' in 'project_branches'", FillProjectBranchesBranchType.class)
+ .add(4025, "Make 'branch_type' in 'project_branches' not nullable", MakeProjectBranchesBranchTypeNotNullable.class)
+ .add(4026, "Drop column 'key_type' in table 'project_branches'", DropProjectBranchesKeyType.class)
+
+ ;
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DropProjectBranchesKeyType.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DropProjectBranchesKeyType.java
new file mode 100644
index 00000000000..2965fb23219
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DropProjectBranchesKeyType.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.v85;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropProjectBranchesKeyType extends DdlChange {
+ private static final String TABLE_NAME = "project_branches";
+
+ public DropProjectBranchesKeyType(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("project_branches_kee_key_type").build());
+ context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "key_type").build());
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE_NAME)
+ .setUnique(true)
+ .setName("uniq_project_branches")
+ .addColumn("branch_type")
+ .addColumn("project_uuid")
+ .addColumn("kee")
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/FillProjectBranchesBranchType.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/FillProjectBranchesBranchType.java
new file mode 100644
index 00000000000..38796accc31
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/FillProjectBranchesBranchType.java
@@ -0,0 +1,46 @@
+/*
+ * 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.v85;
+
+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 FillProjectBranchesBranchType extends DataChange {
+ public FillProjectBranchesBranchType(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select("select uuid, key_type from project_branches where branch_type is null");
+ massUpdate.update("update project_branches set branch_type = ? where uuid = ?");
+ massUpdate.execute((row, update) -> {
+ String uuid = row.getString(1);
+ String type = row.getString(2);
+
+ update.setString(1, type);
+ update.setString(2, uuid);
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/KeyType.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectBranchesBranchTypeNotNullable.java
index 1ee617a0083..838dd8f9343 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/KeyType.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectBranchesBranchTypeNotNullable.java
@@ -17,10 +17,27 @@
* 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.db.component;
+package org.sonar.server.platform.db.migration.version.v85;
-public enum KeyType {
- BRANCH,
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
- PULL_REQUEST
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeProjectBranchesBranchTypeNotNullable extends DdlChange {
+ public MakeProjectBranchesBranchTypeNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), "project_branches")
+ .updateColumn(newVarcharColumnDefBuilder()
+ .setLimit(12)
+ .setIsNullable(false)
+ .setColumnName("branch_type")
+ .build()).build());
+ }
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/DropProjectBranchesKeyTypeTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/DropProjectBranchesKeyTypeTest.java
new file mode 100644
index 00000000000..c8a3daee649
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/DropProjectBranchesKeyTypeTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.v85;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DropProjectBranchesKeyTypeTest {
+ private static final String TABLE_NAME = "project_branches";
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropProjectBranchesKeyTypeTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropProjectBranchesKeyType(db.database());
+
+ @Test
+ public void drops_table() throws SQLException {
+ insertData(1, "PULL_REQUEST", "PULL_REQUEST");
+ insertData(2, "BRANCH", "BRANCH");
+
+ db.assertColumnDefinition(TABLE_NAME, "key_type", Types.VARCHAR, 12, false);
+
+ underTest.execute();
+ db.assertIndexDoesNotExist(TABLE_NAME, "project_branches_kee_key_type");
+ db.assertUniqueIndex(TABLE_NAME, "uniq_project_branches", "branch_type", "project_uuid", "kee");
+ db.assertColumnDoesNotExist(TABLE_NAME, "key_type");
+ assertThat(db.countRowsOfTable(TABLE_NAME)).isEqualTo(2);
+ }
+
+ private void insertData(int id, String keyType, @Nullable String branchType) {
+ db.executeInsert(TABLE_NAME,
+ "uuid", "uuid" + id,
+ "project_uuid", "project" + id,
+ "kee", "key" + id,
+ "key_type", keyType,
+ "created_at", id,
+ "updated_at", id + 1,
+ "need_issue_sync", true,
+ "branch_type", branchType
+ );
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/FillProjectBranchesBranchTypeTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/FillProjectBranchesBranchTypeTest.java
new file mode 100644
index 00000000000..258730a1427
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/FillProjectBranchesBranchTypeTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.v85;
+
+import java.sql.SQLException;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class FillProjectBranchesBranchTypeTest {
+ private static final String TABLE_NAME = "project_branches";
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(FillProjectBranchesBranchTypeTest.class, "schema.sql");
+
+ private MigrationStep underTest = new FillProjectBranchesBranchType(db.database());
+
+ @Test
+ public void drops_table() throws SQLException {
+ insertData(1, "PULL_REQUEST", "PULL_REQUEST");
+ insertData(2, "PULL_REQUEST", null);
+ insertData(3, "BRANCH", null);
+ insertData(4, "BRANCH", "BRANCH");
+
+ underTest.execute();
+ assertThat(db.select("select uuid, key_type, branch_type from project_branches"))
+ .extracting(m -> m.get("UUID"), m -> m.get("KEY_TYPE"), m -> m.get("BRANCH_TYPE"))
+ .containsOnly(
+ tuple("uuid1", "PULL_REQUEST", "PULL_REQUEST"),
+ tuple("uuid2", "PULL_REQUEST", "PULL_REQUEST"),
+ tuple("uuid3", "BRANCH", "BRANCH"),
+ tuple("uuid4", "BRANCH", "BRANCH"));
+
+ }
+
+ private void insertData(int id, String keyType, @Nullable String branchType) {
+ db.executeInsert(TABLE_NAME,
+ "uuid", "uuid" + id,
+ "project_uuid", "project" + id,
+ "kee", "key" + id,
+ "key_type", keyType,
+ "created_at", id,
+ "updated_at", id + 1,
+ "need_issue_sync", true,
+ "branch_type", branchType
+ );
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectBranchesBranchTypeNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectBranchesBranchTypeNotNullableTest.java
new file mode 100644
index 00000000000..1c8d1634202
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectBranchesBranchTypeNotNullableTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.v85;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MakeProjectBranchesBranchTypeNotNullableTest {
+ private static final String TABLE_NAME = "project_branches";
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeProjectBranchesBranchTypeNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeProjectBranchesBranchTypeNotNullable(db.database());
+
+ @Test
+ public void drops_table() throws SQLException {
+ insertData(1, "PULL_REQUEST", "PULL_REQUEST");
+ insertData(2, "BRANCH", "BRANCH");
+
+ db.assertColumnDefinition(TABLE_NAME, "branch_type", Types.VARCHAR, 12, true);
+
+ underTest.execute();
+
+ db.assertColumnDefinition(TABLE_NAME, "branch_type", Types.VARCHAR, 12, false);
+ assertThat(db.countRowsOfTable(TABLE_NAME)).isEqualTo(2);
+ }
+
+ private void insertData(int id, String keyType, @Nullable String branchType) {
+ db.executeInsert(TABLE_NAME,
+ "uuid", "uuid" + id,
+ "project_uuid", "project" + id,
+ "kee", "key" + id,
+ "key_type", keyType,
+ "created_at", id,
+ "updated_at", id + 1,
+ "need_issue_sync", true,
+ "branch_type", branchType
+ );
+ }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/DropProjectBranchesKeyTypeTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/DropProjectBranchesKeyTypeTest/schema.sql
new file mode 100644
index 00000000000..93927b5fb55
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/DropProjectBranchesKeyTypeTest/schema.sql
@@ -0,0 +1,16 @@
+CREATE TABLE "PROJECT_BRANCHES"(
+ "UUID" VARCHAR(50) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "KEE" VARCHAR(255) NOT NULL,
+ "BRANCH_TYPE" VARCHAR(12) NOT NULL,
+ "MERGE_BRANCH_UUID" VARCHAR(50),
+ "KEY_TYPE" VARCHAR(12) NOT NULL,
+ "PULL_REQUEST_BINARY" BLOB,
+ "MANUAL_BASELINE_ANALYSIS_UUID" VARCHAR(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "EXCLUDE_FROM_PURGE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "NEED_ISSUE_SYNC" BOOLEAN NOT NULL
+);
+ALTER TABLE "PROJECT_BRANCHES" ADD CONSTRAINT "PK_PROJECT_BRANCHES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE_KEY_TYPE" ON "PROJECT_BRANCHES"("PROJECT_UUID", "KEE", "KEY_TYPE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/FillProjectBranchesBranchTypeTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/FillProjectBranchesBranchTypeTest/schema.sql
new file mode 100644
index 00000000000..094c3286a05
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/FillProjectBranchesBranchTypeTest/schema.sql
@@ -0,0 +1,16 @@
+CREATE TABLE "PROJECT_BRANCHES"(
+ "UUID" VARCHAR(50) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "KEE" VARCHAR(255) NOT NULL,
+ "BRANCH_TYPE" VARCHAR(12),
+ "MERGE_BRANCH_UUID" VARCHAR(50),
+ "KEY_TYPE" VARCHAR(12) NOT NULL,
+ "PULL_REQUEST_BINARY" BLOB,
+ "MANUAL_BASELINE_ANALYSIS_UUID" VARCHAR(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "EXCLUDE_FROM_PURGE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "NEED_ISSUE_SYNC" BOOLEAN NOT NULL
+);
+ALTER TABLE "PROJECT_BRANCHES" ADD CONSTRAINT "PK_PROJECT_BRANCHES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE_KEY_TYPE" ON "PROJECT_BRANCHES"("PROJECT_UUID", "KEE", "KEY_TYPE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeProjectBranchesBranchTypeNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeProjectBranchesBranchTypeNotNullableTest/schema.sql
new file mode 100644
index 00000000000..094c3286a05
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeProjectBranchesBranchTypeNotNullableTest/schema.sql
@@ -0,0 +1,16 @@
+CREATE TABLE "PROJECT_BRANCHES"(
+ "UUID" VARCHAR(50) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "KEE" VARCHAR(255) NOT NULL,
+ "BRANCH_TYPE" VARCHAR(12),
+ "MERGE_BRANCH_UUID" VARCHAR(50),
+ "KEY_TYPE" VARCHAR(12) NOT NULL,
+ "PULL_REQUEST_BINARY" BLOB,
+ "MANUAL_BASELINE_ANALYSIS_UUID" VARCHAR(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "EXCLUDE_FROM_PURGE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "NEED_ISSUE_SYNC" BOOLEAN NOT NULL
+);
+ALTER TABLE "PROJECT_BRANCHES" ADD CONSTRAINT "PK_PROJECT_BRANCHES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE_KEY_TYPE" ON "PROJECT_BRANCHES"("PROJECT_UUID", "KEE", "KEY_TYPE");
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ListAction.java
index 13326b68047..17292c537e5 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ListAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ListAction.java
@@ -20,6 +20,7 @@
package org.sonar.server.newcodeperiod.ws;
import java.util.Collection;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -86,6 +87,7 @@ public class ListAction implements NewCodePeriodsWsAction {
userSession.checkProjectPermission(UserRole.ADMIN, project);
Collection<BranchDto> branches = dbClient.branchDao().selectByProject(dbSession, project).stream()
.filter(b -> b.getBranchType() == BranchType.BRANCH)
+ .sorted(Comparator.comparing(BranchDto::getKey))
.collect(toList());
List<NewCodePeriodDto> newCodePeriods = newCodePeriodDao.selectAllByProject(dbSession, project.getUuid());