]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13444 add 'need_issue_sync' to 'project_branches' table
authorJacek <jacek.poreda@sonarsource.com>
Fri, 29 May 2020 13:11:50 +0000 (15:11 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 26 Jun 2020 20:04:56 +0000 (20:04 +0000)
15 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDtoTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSync.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNull.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSync.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSyncTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNullTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSyncTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSyncTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNullTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSyncTest/schema.sql [new file with mode: 0644]

index bb99932bbb966f1fa0272c699e0c1a02c1a61dc2..202d9b2b9ddeba14bb73ab3ea466a508fa9a7001 100644 (file)
@@ -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 +
       '}';
   }
 }
index 50a30adbbc9566c1bcad7cd3196822b7e2a4ee80..dc46e289580f9b6974df0b2be0ad60c6683e7e03 100644 (file)
     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>
 
index 8367ba17026196c85c1c3567a5d965d659694c27..f0f66ad073915d98aba6b404b1fd3b2ab088d360 100644 (file)
@@ -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");
index 5fcb5c489f10c5f485f610e52c8798acf225fe1f..48a786bde79b8d5c43e826283faa01c7c94832a9 100644 (file)
@@ -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 (file)
index 0000000..e43845b
--- /dev/null
@@ -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());
+  }
+}
index af5f746ee8e9d285b0b2a7bd6ab2c0bf4673a20e..490e434c402bd197df42020ea98137498b9df8f2 100644 (file)
@@ -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 (file)
index 0000000..f4603a8
--- /dev/null
@@ -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 (file)
index 0000000..f2810cc
--- /dev/null
@@ -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;
+    });
+  }
+}
index 55d36072a298eb1f0a9031b5fc7d43a7d974bd65..e298cf83538a7b3781f4a00f81f5f187e77b8598 100644 (file)
@@ -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 (file)
index 0000000..dd7aa73
--- /dev/null
@@ -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 (file)
index 0000000..5066e58
--- /dev/null
@@ -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 (file)
index 0000000..6a36bed
--- /dev/null
@@ -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 (file)
index 0000000..04995e9
--- /dev/null
@@ -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 (file)
index 0000000..de231f6
--- /dev/null
@@ -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 (file)
index 0000000..de231f6
--- /dev/null
@@ -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");