aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2020-05-29 15:11:50 +0200
committersonartech <sonartech@sonarsource.com>2020-06-26 20:04:56 +0000
commit9b49b87d256933a17e864220fd070296fd2366fc (patch)
treef2df2f6003e4c989d26ae1dbe4ead09a0c27a8ed /server
parent88131a33e07fe611f32883079614d1e768f60076 (diff)
downloadsonarqube-9b49b87d256933a17e864220fd070296fd2366fc.tar.gz
sonarqube-9b49b87d256933a17e864220fd070296fd2366fc.zip
SONAR-13444 add 'need_issue_sync' to 'project_branches' table
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java16
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml45
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl3
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDtoTest.java2
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSync.java43
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java4
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNull.java43
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSync.java44
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java1
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSyncTest.java66
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNullTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSyncTest.java75
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSyncTest/schema.sql15
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNullTest/schema.sql16
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSyncTest/schema.sql16
15 files changed, 406 insertions, 26 deletions
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 bb99932bbb9..202d9b2b9dd 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
@@ -90,6 +90,8 @@ public class BranchDto {
private boolean excludeFromPurge;
+ private boolean needIssueSync = false;
+
public String getUuid() {
return uuid;
}
@@ -200,6 +202,14 @@ public class BranchDto {
}
}
+ public boolean isNeedIssueSync() {
+ return needIssueSync;
+ }
+
+ public void setNeedIssueSync(boolean needIssueSync) {
+ this.needIssueSync = needIssueSync;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -213,12 +223,13 @@ public class BranchDto {
Objects.equals(projectUuid, branchDto.projectUuid) &&
Objects.equals(kee, branchDto.kee) &&
branchType == branchDto.branchType &&
- Objects.equals(mergeBranchUuid, branchDto.mergeBranchUuid);
+ Objects.equals(mergeBranchUuid, branchDto.mergeBranchUuid) &&
+ needIssueSync == branchDto.needIssueSync;
}
@Override
public int hashCode() {
- return Objects.hash(uuid, projectUuid, kee, branchType, mergeBranchUuid);
+ return Objects.hash(uuid, projectUuid, kee, branchType, mergeBranchUuid, needIssueSync);
}
@Override
@@ -231,6 +242,7 @@ public class BranchDto {
", branchType=" + branchType +
", mergeBranchUuid='" + mergeBranchUuid + '\'' +
", excludeFromPurge=" + excludeFromPurge +
+ ", needIssueSync=" + needIssueSync +
'}';
}
}
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 50a30adbbc9..dc46e289580 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
@@ -10,32 +10,35 @@
pb.branch_type as branchType,
pb.merge_branch_uuid as mergeBranchUuid,
pb.pull_request_binary as pullRequestBinary,
- pb.exclude_from_purge as excludeFromPurge
+ pb.exclude_from_purge as excludeFromPurge,
+ pb.need_issue_sync as needIssueSync
</sql>
<insert id="insert" parameterType="map" useGeneratedKeys="false">
insert into project_branches (
- uuid,
- project_uuid,
- kee,
- key_type,
- branch_type,
- merge_branch_uuid,
- pull_request_binary,
- created_at,
- updated_at,
- exclude_from_purge
+ uuid,
+ project_uuid,
+ kee,
+ key_type,
+ branch_type,
+ merge_branch_uuid,
+ pull_request_binary,
+ created_at,
+ updated_at,
+ exclude_from_purge,
+ need_issue_sync
) values (
- #{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},
- #{now, jdbcType=BIGINT},
- #{now, jdbcType=BIGINT},
- #{dto.excludeFromPurge, jdbcType=BOOLEAN}
+ #{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},
+ #{now, jdbcType=BIGINT},
+ #{now, jdbcType=BIGINT},
+ #{dto.excludeFromPurge, jdbcType=BOOLEAN},
+ #{dto.needIssueSync, jdbcType=BOOLEAN}
)
</insert>
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 8367ba17026..f0f66ad0739 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -643,7 +643,8 @@ CREATE TABLE "PROJECT_BRANCHES"(
"MANUAL_BASELINE_ANALYSIS_UUID" VARCHAR(40),
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL,
- "EXCLUDE_FROM_PURGE" BOOLEAN DEFAULT FALSE 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-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 5fcb5c489f1..48a786bde79 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}");
+ "projectUuid='U2', kee='K1', keyType=null, branchType=BRANCH, mergeBranchUuid='U3', excludeFromPurge=true, needIssueSync=false}");
}
@Test
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSync.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSync.java
new file mode 100644
index 00000000000..e43845bedb9
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSync.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.v84;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class AddProjectBranchesNeedIssueSync extends DdlChange {
+ public AddProjectBranchesNeedIssueSync(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), "project_branches")
+ .addColumn(BooleanColumnDef.newBooleanColumnDefBuilder()
+ .setColumnName("need_issue_sync")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .build())
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java
index af5f746ee8e..490e434c402 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java
@@ -776,6 +776,10 @@ public class DbVersion84 implements DbVersion {
.add(3800, "Remove favourites for components with qualifiers 'DIR', 'FIL', 'UTS'", RemoveFilesFavouritesFromProperties.class)
.add(3801, "Create 'SESSION_TOKENS' table", CreateSessionTokensTable.class)
.add(3802, "Create 'SAML_MESSAGE_IDS' table", CreateSamlMessageIdsTable.class)
+
+ .add(3803, "Add 'need_issue_sync' column to 'project_branches' table", AddProjectBranchesNeedIssueSync.class)
+ .add(3804, "Populate 'need_issue_sync' of 'project_branches'", PopulateProjectBranchesNeedIssueSync.class)
+ .add(3805, "Make 'need_issue_sync' of 'project_branches' not null", MakeProjectBranchesNeedIssueSyncNonNull.class)
;
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNull.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNull.java
new file mode 100644
index 00000000000..f4603a811ab
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNull.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.v84;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class MakeProjectBranchesNeedIssueSyncNonNull extends DdlChange {
+ public MakeProjectBranchesNeedIssueSyncNonNull(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), "project_branches")
+ .updateColumn(BooleanColumnDef.newBooleanColumnDefBuilder()
+ .setColumnName("need_issue_sync")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .build())
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSync.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSync.java
new file mode 100644
index 00000000000..f2810cc2dac
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSync.java
@@ -0,0 +1,44 @@
+/*
+ * 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.v84;
+
+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 PopulateProjectBranchesNeedIssueSync extends DataChange {
+ public PopulateProjectBranchesNeedIssueSync(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select("select uuid from project_branches where need_issue_sync is null");
+ massUpdate.update("update project_branches set need_issue_sync = ? where uuid = ?");
+ massUpdate.execute((row, update) -> {
+ String uuid = row.getString(1);
+ update.setBoolean(1, false);
+ update.setString(2, uuid);
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java
index 55d36072a29..e298cf83538 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java
@@ -21,7 +21,6 @@ package org.sonar.server.platform.db.migration.version.v83;
import org.junit.Test;
import org.sonar.server.platform.db.migration.version.DbVersion;
-import org.sonar.server.platform.db.migration.version.v84.DbVersion84;
import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationNotEmpty;
import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSyncTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSyncTest.java
new file mode 100644
index 00000000000..dd7aa733dbf
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSyncTest.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.v84;
+
+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 AddProjectBranchesNeedIssueSyncTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddProjectBranchesNeedIssueSyncTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddProjectBranchesNeedIssueSync(db.database());
+
+ @Before
+ public void setup() {
+ insertProjectBranches("uuid-1");
+ insertProjectBranches("uuid-2");
+ insertProjectBranches("uuid-3");
+ }
+
+ @Test
+ public void add_need_issue_sync_column_to_project_branches() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("project_branches", "need_issue_sync", Types.BOOLEAN, null, true);
+
+ assertThat(db.countSql("select count(uuid) from project_branches"))
+ .isEqualTo(3);
+ }
+
+ private void insertProjectBranches(String uuid) {
+ db.executeInsert("project_branches",
+ "uuid", uuid,
+ "project_uuid", "name",
+ "kee", uuid,
+ "key_type", "KEY_TYPE",
+ "created_at", System.currentTimeMillis(),
+ "updated_at", System.currentTimeMillis(),
+ "exclude_from_purge", false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNullTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNullTest.java
new file mode 100644
index 00000000000..5066e588447
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNullTest.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.v84;
+
+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.BOOLEAN;
+
+public class MakeProjectBranchesNeedIssueSyncNonNullTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeProjectBranchesNeedIssueSyncNonNullTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeProjectBranchesNeedIssueSyncNonNull(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("project_branches", "need_issue_sync", BOOLEAN, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSyncTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSyncTest.java
new file mode 100644
index 00000000000..6a36bed84a3
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSyncTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.v84;
+
+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 PopulateProjectBranchesNeedIssueSyncTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateProjectBranchesNeedIssueSyncTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateProjectBranchesNeedIssueSync(db.database());
+
+ @Test
+ public void populate_need_issue_sync() throws SQLException {
+ insertProjectBranches("uuid-1");
+ insertProjectBranches("uuid-2");
+ insertProjectBranches("uuid-3");
+
+ underTest.execute();
+
+ verifyNeedIssueSyncIsNotNull();
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ insertProjectBranches("uuid-1");
+ insertProjectBranches("uuid-2");
+ insertProjectBranches("uuid-3");
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ verifyNeedIssueSyncIsNotNull();
+ }
+
+ private void verifyNeedIssueSyncIsNotNull() {
+ assertThat(db.select("select need_issue_sync from project_branches where need_issue_sync is null")).isEmpty();
+ }
+
+ private void insertProjectBranches(String uuid) {
+ db.executeInsert("project_branches",
+ "uuid", uuid,
+ "project_uuid", "name",
+ "kee", uuid,
+ "key_type", "KEY_TYPE",
+ "created_at", System.currentTimeMillis(),
+ "updated_at", System.currentTimeMillis(),
+ "exclude_from_purge", false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSyncTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSyncTest/schema.sql
new file mode 100644
index 00000000000..04995e9560f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSyncTest/schema.sql
@@ -0,0 +1,15 @@
+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
+);
+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/v84/MakeProjectBranchesNeedIssueSyncNonNullTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNullTest/schema.sql
new file mode 100644
index 00000000000..de231f6b163
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNullTest/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
+);
+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/v84/PopulateProjectBranchesNeedIssueSyncTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSyncTest/schema.sql
new file mode 100644
index 00000000000..de231f6b163
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSyncTest/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
+);
+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");