From 72152a7bfcc6748b396a1649d8af229433547b0c Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Mon, 2 Oct 2017 17:37:22 +0200 Subject: [PATCH] SONAR-9899 Remove all references to branches of type PR --- .../org/sonar/db/version/schema-h2.ddl | 4 +- .../org/sonar/db/component/BranchDao.java | 5 +-- .../org/sonar/db/component/BranchDto.java | 45 ++----------------- .../org/sonar/db/component/BranchKeyType.java | 35 --------------- .../org/sonar/db/component/BranchMapper.java | 3 +- .../org/sonar/db/component/BranchMapper.xml | 10 +---- .../org/sonar/db/component/BranchDaoTest.java | 34 +++----------- .../sonar/db/component/ComponentTesting.java | 3 -- .../v66/AddIndexOnProjectBranchesKey.java | 5 --- .../v66/CreateTableProjectBranches.java | 10 ----- .../v66/PopulateMainProjectBranches.java | 16 +++---- .../v66/CreateTableProjectBranchesTest.java | 2 - .../v66/PopulateMainProjectBranchesTest.java | 9 ++-- .../initial.sql | 4 +- .../server/component/ComponentUpdater.java | 3 -- .../component/BranchPersister.java | 3 -- .../server/projectbranch/ws/DeleteAction.java | 3 +- .../server/projectbranch/ws/ListAction.java | 2 - .../server/projectbranch/ws/RenameAction.java | 3 +- .../component/ComponentUpdaterTest.java | 3 -- 20 files changed, 28 insertions(+), 174 deletions(-) delete mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchKeyType.java diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl index f4ea81d864e..0aab8ac7160 100644 --- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl +++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl @@ -717,13 +717,11 @@ CREATE UNIQUE INDEX "PLUGINS_KEY" ON "PLUGINS" ("KEE"); CREATE TABLE "PROJECT_BRANCHES" ( "UUID" VARCHAR(50) NOT NULL PRIMARY KEY, "PROJECT_UUID" VARCHAR(50) NOT NULL, - "KEE_TYPE" VARCHAR(6) NOT NULL, "KEE" VARCHAR(255) NOT NULL, "BRANCH_TYPE" VARCHAR(5), "MERGE_BRANCH_UUID" VARCHAR(50), - "PULL_REQUEST_TITLE" VARCHAR(4000), "CREATED_AT" BIGINT NOT NULL, "UPDATED_AT" BIGINT NOT NULL ); CREATE UNIQUE INDEX "PK_PROJECT_BRANCHES" ON "PROJECT_BRANCHES" ("UUID"); -CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE" ON "PROJECT_BRANCHES" ("PROJECT_UUID", "KEE_TYPE", "KEE"); +CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE" ON "PROJECT_BRANCHES" ("PROJECT_UUID", "KEE"); 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 ae6558869cf..1b30cf9ae09 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 @@ -22,7 +22,6 @@ package org.sonar.db.component; import java.util.Collection; import java.util.List; import java.util.Optional; -import javax.annotation.Nullable; import org.sonar.api.utils.System2; import org.sonar.db.Dao; import org.sonar.db.DbSession; @@ -54,8 +53,8 @@ public class BranchDao implements Dao { return mapper(dbSession).updateMainBranchName(projectUuid, newBranchKey, now); } - public Optional selectByKey(DbSession dbSession, String projectUuid, BranchKeyType keyType, @Nullable String key) { - return Optional.ofNullable(mapper(dbSession).selectByKey(projectUuid, keyType, key)); + public Optional selectByKey(DbSession dbSession, String projectUuid, String key) { + return Optional.ofNullable(mapper(dbSession).selectByKey(projectUuid, key)); } public Collection 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 655260116e4..65b46912c6d 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 @@ -48,24 +48,14 @@ public class BranchDto { private String projectUuid; /** - * Not null. - */ - private BranchKeyType keeType; - - /** - * If {@link #keeType} is {@link BranchKeyType#BRANCH}, then name of branch, for example - * "feature/foo". - * - * If {@link #keeType} is {@link BranchKeyType#PR}, then id of the pull request, for - * example "1204". + * Name of branch, for example "feature/foo". */ private String kee; /** - * Value is mandatory when {@link #keeType} is {@link BranchKeyType#BRANCH}. - * Otherwise it is null. + * Branch type, as provided by {@link BranchType}. + * Not null. */ - @Nullable private BranchType branchType; /** @@ -78,12 +68,6 @@ public class BranchDto { @Nullable private String mergeBranchUuid; - /** - * Optional title of pull requests - */ - @Nullable - private String pullRequestTitle; - public String getUuid() { return uuid; } @@ -106,15 +90,6 @@ public class BranchDto { return projectUuid.equals(uuid); } - public BranchKeyType getKeeType() { - return keeType; - } - - public BranchDto setKeeType(BranchKeyType t) { - this.keeType = t; - return this; - } - /** * This is the getter used by MyBatis mapper. */ @@ -139,7 +114,6 @@ public class BranchDto { return this; } - @Nullable public BranchType getBranchType() { return branchType; } @@ -159,27 +133,14 @@ public class BranchDto { return this; } - @Nullable - public String getPullRequestTitle() { - return pullRequestTitle; - } - - public BranchDto setPullRequestTitle(@Nullable String s) { - checkArgument(s == null || s.length() <= 4000, "Maximum length of pull request title is 4000: %s", s); - this.pullRequestTitle = s; - return this; - } - @Override public String toString() { StringBuilder sb = new StringBuilder("BranchDto{"); sb.append("uuid='").append(uuid).append('\''); sb.append(", projectUuid='").append(projectUuid).append('\''); - sb.append(", keeType=").append(keeType); sb.append(", kee='").append(kee).append('\''); sb.append(", branchType=").append(branchType); sb.append(", mergeBranchUuid='").append(mergeBranchUuid).append('\''); - sb.append(", pullRequestTitle='").append(pullRequestTitle).append('\''); sb.append('}'); return sb.toString(); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchKeyType.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchKeyType.java deleted file mode 100644 index cc6ca0a85aa..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchKeyType.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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.db.component; - -/** - * Supported values in column project_branches.kee_type - */ -public enum BranchKeyType { - /** - * Branch, whatever long or short, main or not. - */ - BRANCH, - - /** - * Pull request - */ - PR -} 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 d1c08ed6bc0..ec37acbc8dc 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 @@ -31,8 +31,7 @@ public interface BranchMapper { int updateMainBranchName(@Param("projectUuid") String projectUuid, @Param("newBranchName") String newBranchName, @Param("now") long now); - BranchDto selectByKey(@Param("projectUuid") String projectUuid, - @Param("keyType") BranchKeyType keyType, @Param("key") String key); + BranchDto selectByKey(@Param("projectUuid") String projectUuid, @Param("key") String key); BranchDto selectByUuid(@Param("uuid") String uuid); 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 dd520667833..f14a166566b 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 @@ -5,32 +5,26 @@ pb.uuid as uuid, pb.project_uuid as projectUuid, - pb.kee_type as keeType, pb.kee as kee, pb.branch_type as branchType, - pb.merge_branch_uuid as mergeBranchUuid, - pb.pull_request_title as pullRequestTitle + pb.merge_branch_uuid as mergeBranchUuid insert into project_branches ( uuid, project_uuid, - kee_type, kee, branch_type, merge_branch_uuid, - pull_request_title, created_at, updated_at ) values ( #{dto.uuid, jdbcType=VARCHAR}, #{dto.projectUuid, jdbcType=VARCHAR}, - #{dto.keeType, jdbcType=VARCHAR}, #{dto.kee, jdbcType=VARCHAR}, #{dto.branchType, jdbcType=VARCHAR}, #{dto.mergeBranchUuid, jdbcType=VARCHAR}, - #{dto.pullRequestTitle, jdbcType=VARCHAR}, #{now, jdbcType=BIGINT}, #{now, jdbcType=BIGINT} ) @@ -49,7 +43,6 @@ update project_branches set merge_branch_uuid = #{dto.mergeBranchUuid, jdbcType=VARCHAR}, - pull_request_title = #{dto.pullRequestTitle, jdbcType=VARCHAR}, updated_at = #{now, jdbcType=BIGINT} where uuid = #{dto.uuid, jdbcType=VARCHAR} @@ -60,7 +53,6 @@ from project_branches pb where pb.project_uuid = #{projectUuid, jdbcType=VARCHAR} and - pb.kee_type = #{keyType, jdbcType=VARCHAR} and pb.kee = #{key, jdbcType=VARCHAR} diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java index f7f20dda309..0932817bcbd 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java @@ -37,8 +37,8 @@ import static org.assertj.core.api.Assertions.entry; public class BranchDaoTest { private static final long NOW = 1_000L; - private static final String SELECT_FROM = "select project_uuid as \"projectUuid\", uuid as \"uuid\", branch_type as \"branchType\", kee_type as \"keeType\", " + - "kee as \"kee\", merge_branch_uuid as \"mergeBranchUuid\", pull_request_title as \"pullRequestTitle\", created_at as \"createdAt\", updated_at as \"updatedAt\" " + + private static final String SELECT_FROM = "select project_uuid as \"projectUuid\", uuid as \"uuid\", branch_type as \"branchType\", " + + "kee as \"kee\", merge_branch_uuid as \"mergeBranchUuid\", created_at as \"createdAt\", updated_at as \"updatedAt\" " + "from project_branches "; private System2 system2 = new TestSystem2().setNow(NOW); @@ -54,7 +54,6 @@ public class BranchDaoTest { dto.setProjectUuid("U1"); dto.setUuid("U2"); dto.setBranchType(BranchType.SHORT); - dto.setKeeType(BranchKeyType.BRANCH); dto.setKey("feature/foo"); underTest.insert(dbSession, dto); @@ -64,10 +63,8 @@ public class BranchDaoTest { entry("projectUuid", "U1"), entry("uuid", "U2"), entry("branchType", "SHORT"), - entry("keeType", "BRANCH"), entry("kee", "feature/foo"), entry("mergeBranchUuid", null), - entry("pullRequestTitle", null), entry("createdAt", 1_000L), entry("updatedAt", 1_000L)); } @@ -78,7 +75,6 @@ public class BranchDaoTest { dto.setProjectUuid("U1"); dto.setUuid("U1"); dto.setBranchType(BranchType.LONG); - dto.setKeeType(BranchKeyType.BRANCH); dto.setKey("feature"); underTest.insert(dbSession, dto); @@ -86,17 +82,14 @@ public class BranchDaoTest { dto2.setProjectUuid("U2"); dto2.setUuid("U2"); dto2.setBranchType(BranchType.LONG); - dto2.setKeeType(BranchKeyType.BRANCH); dto2.setKey("branch"); underTest.insert(dbSession, dto2); underTest.updateMainBranchName(dbSession, "U1", "master"); - BranchDto loaded = underTest.selectByKey(dbSession, "U1", BranchKeyType.BRANCH, "master").get(); + BranchDto loaded = underTest.selectByKey(dbSession, "U1", "master").get(); assertThat(loaded.getMergeBranchUuid()).isNull(); - assertThat(loaded.getPullRequestTitle()).isNull(); assertThat(loaded.getProjectUuid()).isEqualTo("U1"); assertThat(loaded.getBranchType()).isEqualTo(BranchType.LONG); - assertThat(loaded.getKeeType()).isEqualTo(BranchKeyType.BRANCH); } @Test @@ -105,10 +98,8 @@ public class BranchDaoTest { dto.setProjectUuid(repeat("a", 50)); dto.setUuid(repeat("b", 50)); dto.setBranchType(BranchType.SHORT); - dto.setKeeType(BranchKeyType.BRANCH); dto.setKey(repeat("c", 255)); dto.setMergeBranchUuid(repeat("d", 50)); - dto.setPullRequestTitle(repeat("e", 4_000)); underTest.insert(dbSession, dto); @@ -117,7 +108,6 @@ public class BranchDaoTest { assertThat((String) map.get("uuid")).contains("b").isEqualTo(dto.getUuid()); assertThat((String) map.get("kee")).contains("c").isEqualTo(dto.getKey()); assertThat((String) map.get("mergeBranchUuid")).contains("d").isEqualTo(dto.getMergeBranchUuid()); - assertThat((String) map.get("pullRequestTitle")).contains("e").isEqualTo(dto.getPullRequestTitle()); } @Test @@ -126,26 +116,21 @@ public class BranchDaoTest { dto.setProjectUuid("U1"); dto.setUuid("U2"); dto.setBranchType(BranchType.LONG); - dto.setKeeType(BranchKeyType.BRANCH); dto.setKey("foo"); underTest.insert(dbSession, dto); // the fields that can be updated dto.setMergeBranchUuid("U3"); - dto.setPullRequestTitle("theTitle"); // the fields that can't be updated. New values are ignored. dto.setProjectUuid("ignored"); dto.setBranchType(BranchType.SHORT); - dto.setKeeType(BranchKeyType.PR); underTest.upsert(dbSession, dto); - BranchDto loaded = underTest.selectByKey(dbSession, "U1", BranchKeyType.BRANCH, "foo").get(); + BranchDto loaded = underTest.selectByKey(dbSession, "U1", "foo").get(); assertThat(loaded.getMergeBranchUuid()).isEqualTo("U3"); - assertThat(loaded.getPullRequestTitle()).isEqualTo("theTitle"); assertThat(loaded.getProjectUuid()).isEqualTo("U1"); assertThat(loaded.getBranchType()).isEqualTo(BranchType.LONG); - assertThat(loaded.getKeeType()).isEqualTo(BranchKeyType.BRANCH); } @Test @@ -154,7 +139,6 @@ public class BranchDaoTest { mainBranch.setProjectUuid("U1"); mainBranch.setUuid("U1"); mainBranch.setBranchType(BranchType.LONG); - mainBranch.setKeeType(BranchKeyType.BRANCH); mainBranch.setKey("master"); underTest.insert(dbSession, mainBranch); @@ -162,26 +146,20 @@ public class BranchDaoTest { featureBranch.setProjectUuid("U1"); featureBranch.setUuid("U2"); featureBranch.setBranchType(BranchType.SHORT); - featureBranch.setKeeType(BranchKeyType.BRANCH); featureBranch.setKey("feature/foo"); featureBranch.setMergeBranchUuid("U3"); underTest.insert(dbSession, featureBranch); // select the feature branch - BranchDto loaded = underTest.selectByKey(dbSession, "U1", BranchKeyType.BRANCH, "feature/foo").get(); + BranchDto loaded = underTest.selectByKey(dbSession, "U1", "feature/foo").get(); assertThat(loaded.getUuid()).isEqualTo(featureBranch.getUuid()); assertThat(loaded.getKey()).isEqualTo(featureBranch.getKey()); assertThat(loaded.getProjectUuid()).isEqualTo(featureBranch.getProjectUuid()); assertThat(loaded.getBranchType()).isEqualTo(featureBranch.getBranchType()); - assertThat(loaded.getKeeType()).isEqualTo(featureBranch.getKeeType()); assertThat(loaded.getMergeBranchUuid()).isEqualTo(featureBranch.getMergeBranchUuid()); - assertThat(loaded.getPullRequestTitle()).isEqualTo(featureBranch.getPullRequestTitle()); - - // select a pull request with same key than the feature branch - assertThat(underTest.selectByKey(dbSession, "U1", BranchKeyType.PR, "feature/foo")).isEmpty(); // select a branch on another project with same branch name - assertThat(underTest.selectByKey(dbSession, "U3", BranchKeyType.BRANCH, "feature/foo")).isEmpty(); + assertThat(underTest.selectByKey(dbSession, "U3", "feature/foo")).isEmpty(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentTesting.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentTesting.java index 27e73d548a5..fa172f5bb5a 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentTesting.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentTesting.java @@ -29,7 +29,6 @@ import org.sonar.db.organization.OrganizationDto; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; -import static org.sonar.db.component.BranchKeyType.BRANCH; import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR; public class ComponentTesting { @@ -209,7 +208,6 @@ public class ComponentTesting { .setUuid(Uuids.createFast()) // MainBranchProjectUuid will be null if it's a main branch .setProjectUuid(projectUuid) - .setKeeType(BRANCH) .setBranchType(branchType); } @@ -226,7 +224,6 @@ public class ComponentTesting { .setKey(key) .setUuid(branchComponent.uuid()) .setProjectUuid(projectUuid) - .setKeeType(BRANCH) .setBranchType(branchType); } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddIndexOnProjectBranchesKey.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddIndexOnProjectBranchesKey.java index 81eee9c9230..09f3fb2950a 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddIndexOnProjectBranchesKey.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddIndexOnProjectBranchesKey.java @@ -42,11 +42,6 @@ public class AddIndexOnProjectBranchesKey extends DdlChange { .setIsNullable(false) .setLimit(50) .build()) - .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder() - .setColumnName("kee_type") - .setIsNullable(false) - .setLimit(6) - .build()) .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder() .setColumnName("kee") .setIsNullable(false) diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableProjectBranches.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableProjectBranches.java index db40d988aec..072e2cf428b 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableProjectBranches.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableProjectBranches.java @@ -47,11 +47,6 @@ public class CreateTableProjectBranches extends DdlChange { .setIsNullable(false) .setLimit(50) .build()) - .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder() - .setColumnName("kee_type") - .setIsNullable(false) - .setLimit(6) - .build()) .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder() .setColumnName("kee") .setIsNullable(false) @@ -67,11 +62,6 @@ public class CreateTableProjectBranches extends DdlChange { .setIsNullable(true) .setLimit(50) .build()) - .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder() - .setColumnName("pull_request_title") - .setIsNullable(true) - .setLimit(4000) - .build()) .addColumn(BigIntegerColumnDef.newBigIntegerColumnDefBuilder() .setColumnName("created_at") .setIsNullable(false) diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranches.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranches.java index 9d66de5abdc..77fca273828 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranches.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranches.java @@ -43,20 +43,18 @@ public class PopulateMainProjectBranches extends DataChange { massUpdate.select("SELECT uuid FROM projects p " + "WHERE p.scope='PRJ' AND p.qualifier='TRK' AND p.main_branch_project_uuid IS NULL " + "AND NOT EXISTS (SELECT uuid FROM project_branches b WHERE b.uuid = p.uuid)"); - massUpdate.update("INSERT INTO project_branches (uuid, project_uuid, kee_type, kee, branch_type, " - + "merge_branch_uuid, pull_request_title, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); + massUpdate.update("INSERT INTO project_branches (uuid, project_uuid, kee, branch_type, " + + "merge_branch_uuid, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)"); massUpdate.rowPluralName("projects"); massUpdate.execute((row, update) -> { String uuid = row.getString(1); update.setString(1, uuid); update.setString(2, uuid); - update.setString(3, "BRANCH"); - update.setString(4, MAIN_BRANCH_NAME); - update.setString(5, "LONG"); - update.setString(6, null); - update.setString(7, null); - update.setLong(8, now); - update.setLong(9, now); + update.setString(3, MAIN_BRANCH_NAME); + update.setString(4, "LONG"); + update.setString(5, null); + update.setLong(6, now); + update.setLong(7, now); return true; }); } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableProjectBranchesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableProjectBranchesTest.java index f8d74a0b115..a7916e617c9 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableProjectBranchesTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableProjectBranchesTest.java @@ -47,11 +47,9 @@ public class CreateTableProjectBranchesTest { db.assertColumnDefinition(TABLE, "uuid", Types.VARCHAR, 50, false); db.assertColumnDefinition(TABLE, "project_uuid", Types.VARCHAR, 50, false); - db.assertColumnDefinition(TABLE, "kee_type", Types.VARCHAR, 6, false); db.assertColumnDefinition(TABLE, "kee", Types.VARCHAR, 255, false); db.assertColumnDefinition(TABLE, "branch_type", Types.VARCHAR, 5, true); db.assertColumnDefinition(TABLE, "merge_branch_uuid", Types.VARCHAR, 50, true); - db.assertColumnDefinition(TABLE, "pull_request_title", Types.VARCHAR, 4000, true); db.assertColumnDefinition(TABLE, "created_at", Types.BIGINT, null, false); db.assertColumnDefinition(TABLE, "updated_at", Types.BIGINT, null, false); db.assertPrimaryKey(TABLE, "pk_" + TABLE, "uuid"); diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranchesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranchesTest.java index 29433a7dc19..e9a10caa2d8 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranchesTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranchesTest.java @@ -54,7 +54,7 @@ public class PopulateMainProjectBranchesTest { underTest.execute(); - assertProjectBranches(tuple("master", project, project, "BRANCH", "LONG", NOW, NOW)); + assertProjectBranches(tuple("master", project, project, "LONG", NOW, NOW)); } @Test @@ -81,13 +81,13 @@ public class PopulateMainProjectBranchesTest { underTest.execute(); - assertProjectBranches(tuple("master", project, project, "BRANCH", "LONG", PAST, PAST)); + assertProjectBranches(tuple("master", project, project, "LONG", PAST, PAST)); } private void assertProjectBranches(Tuple... expectedTuples) { - assertThat(db.select("SELECT KEE, UUID, PROJECT_UUID, KEE_TYPE, BRANCH_TYPE, CREATED_AT, UPDATED_AT FROM PROJECT_BRANCHES") + assertThat(db.select("SELECT KEE, UUID, PROJECT_UUID, BRANCH_TYPE, CREATED_AT, UPDATED_AT FROM PROJECT_BRANCHES") .stream() - .map(map -> new Tuple(map.get("KEE"), map.get("UUID"), map.get("PROJECT_UUID"), map.get("KEE_TYPE"), map.get("BRANCH_TYPE"), map.get("CREATED_AT"), map.get("UPDATED_AT"))) + .map(map -> new Tuple(map.get("KEE"), map.get("UUID"), map.get("PROJECT_UUID"), map.get("BRANCH_TYPE"), map.get("CREATED_AT"), map.get("UPDATED_AT"))) .collect(Collectors.toList())) .containsExactlyInAnyOrder(expectedTuples); } @@ -116,7 +116,6 @@ public class PopulateMainProjectBranchesTest { db.executeInsert("PROJECT_BRANCHES", "uuid", uuid, "project_uuid", uuid, - "kee_type", "BRANCH", "kee", "master", "branch_type", "LONG", "created_at", PAST, diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranchesTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranchesTest/initial.sql index fa29c6921b3..7ae1777df16 100644 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranchesTest/initial.sql +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranchesTest/initial.sql @@ -48,13 +48,11 @@ CREATE INDEX "PROJECTS_QUALIFIER" ON "PROJECTS" ("QUALIFIER"); CREATE TABLE "PROJECT_BRANCHES" ( "UUID" VARCHAR(50) NOT NULL PRIMARY KEY, "PROJECT_UUID" VARCHAR(50) NOT NULL, - "KEE_TYPE" VARCHAR(6) NOT NULL, "KEE" VARCHAR(255) NOT NULL, "BRANCH_TYPE" VARCHAR(5), "MERGE_BRANCH_UUID" VARCHAR(50), - "PULL_REQUEST_TITLE" VARCHAR(4000), "CREATED_AT" BIGINT NOT NULL, "UPDATED_AT" BIGINT NOT NULL ); CREATE UNIQUE INDEX "PK_PROJECT_BRANCHES" ON "PROJECT_BRANCHES" ("UUID"); -CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE" ON "PROJECT_BRANCHES" ("PROJECT_UUID", "KEE_TYPE", "KEE"); +CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE" ON "PROJECT_BRANCHES" ("PROJECT_UUID", "KEE"); diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java index 2ed1f3d02fe..d53d7f15374 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java @@ -32,7 +32,6 @@ import org.sonar.core.util.Uuids; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.BranchDto; -import org.sonar.db.component.BranchKeyType; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.server.es.ProjectIndexer.Cause; @@ -118,11 +117,9 @@ public class ComponentUpdater { private BranchDto createBranch(DbSession session, String componentUuid) { BranchDto branch = new BranchDto() .setBranchType(BranchType.LONG) - .setKeeType(BranchKeyType.BRANCH) .setUuid(componentUuid) .setKey(BranchDto.DEFAULT_MAIN_BRANCH_NAME) .setMergeBranchUuid(null) - .setPullRequestTitle(null) .setProjectUuid(componentUuid); dbClient.branchDao().upsert(session, branch); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersister.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersister.java index 48f1435d5b8..2f6cd178826 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersister.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersister.java @@ -26,7 +26,6 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.BranchDto; -import org.sonar.db.component.BranchKeyType; import org.sonar.db.component.ComponentDto; import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder; import org.sonar.server.computation.task.projectanalysis.analysis.Branch; @@ -87,12 +86,10 @@ public class BranchPersister { dto.setUuid(componentDto.uuid()); // MainBranchProjectUuid will be null if it's a main branch dto.setProjectUuid(firstNonNull(componentDto.getMainBranchProjectUuid(), componentDto.projectUuid())); - dto.setKeeType(BranchKeyType.BRANCH); dto.setKey(branch.getName()); dto.setBranchType(branch.getType()); // merge branch is only present if it's a short living branch dto.setMergeBranchUuid(branch.getMergeBranchUuid().orElse(null)); - dto.setPullRequestTitle(null); return dto; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/DeleteAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/DeleteAction.java index f907be4dfc0..c9a16b50e53 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/DeleteAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/DeleteAction.java @@ -28,7 +28,6 @@ import org.sonar.api.web.UserRole; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.BranchDto; -import org.sonar.db.component.BranchKeyType; import org.sonar.db.component.ComponentDto; import org.sonar.server.component.ComponentCleanerService; import org.sonar.server.component.ComponentFinder; @@ -76,7 +75,7 @@ public class DeleteAction implements BranchWsAction { checkPermission(project); BranchDto branch = checkFoundWithOptional( - dbClient.branchDao().selectByKey(dbSession, project.uuid(), BranchKeyType.BRANCH, branchKey), + dbClient.branchDao().selectByKey(dbSession, project.uuid(), branchKey), "Branch '%s' not found for project '%s'", branchKey, projectKey); if (branch.isMain()) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java index 9ed81f2a73f..7e3486eb313 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java @@ -34,7 +34,6 @@ import org.sonar.api.web.UserRole; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.BranchDto; -import org.sonar.db.component.BranchKeyType; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; @@ -119,7 +118,6 @@ public class ListAction implements BranchWsAction { WsBranches.ListWsResponse.Builder protobufResponse = WsBranches.ListWsResponse.newBuilder(); branches.stream() - .filter(b -> b.getKeeType().equals(BranchKeyType.BRANCH)) .forEach(b -> addBranch(protobufResponse, b, mergeBranchesByUuid, qualityGateMeasuresByComponentUuids.get(b.getUuid()), branchStatisticsByBranchUuid.get(b.getUuid()), analysisDateByBranchUuid.get(b.getUuid()))); WsUtils.writeProtobuf(protobufResponse.build(), request, response); diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/RenameAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/RenameAction.java index 498c629db75..8ffa8abb564 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/RenameAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/RenameAction.java @@ -28,7 +28,6 @@ import org.sonar.api.web.UserRole; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.BranchDto; -import org.sonar.db.component.BranchKeyType; import org.sonar.db.component.ComponentDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.user.UserSession; @@ -71,7 +70,7 @@ public class RenameAction implements BranchWsAction { ComponentDto project = componentFinder.getRootComponentByUuidOrKey(dbSession, null, projectKey); checkPermission(project); - Optional branch = dbClient.branchDao().selectByKey(dbSession, project.uuid(), BranchKeyType.BRANCH, branchKey); + Optional branch = dbClient.branchDao().selectByKey(dbSession, project.uuid(), branchKey); if (branch.isPresent() && !branch.get().isMain()) { throw new IllegalArgumentException("Impossible to update branch name: a branch with name \"" + branchKey + "\" already exists in the project."); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java index 036475dc6fc..fc3784953ce 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java @@ -28,7 +28,6 @@ import org.sonar.api.resources.Scopes; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.BranchDto; -import org.sonar.db.component.BranchKeyType; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.organization.OrganizationDto; @@ -101,10 +100,8 @@ public class ComponentUpdaterTest { Optional branch = db.getDbClient().branchDao().selectByUuid(db.getSession(), returned.uuid()); assertThat(branch).isPresent(); - assertThat(branch.get().getKeeType()).isEqualTo(BranchKeyType.BRANCH); assertThat(branch.get().getKey()).isEqualTo(BranchDto.DEFAULT_MAIN_BRANCH_NAME); assertThat(branch.get().getMergeBranchUuid()).isNull(); - assertThat(branch.get().getPullRequestTitle()).isNull(); assertThat(branch.get().getBranchType()).isEqualTo(BranchType.LONG); assertThat(branch.get().getUuid()).isEqualTo(returned.uuid()); assertThat(branch.get().getProjectUuid()).isEqualTo(returned.uuid()); -- 2.39.5