]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18850 make is_main column work on Oracle
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Fri, 24 Mar 2023 11:18:08 +0000 (12:18 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 4 Apr 2023 20:03:16 +0000 (20:03 +0000)
server/sonar-db-dao/src/it/java/org/sonar/db/component/BranchDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/UpdateIsMainColumnInProjectBranches.java

index 7c38636cfcb1613c9ac0de67224366519b863b33..2cdd6930c6d95b8135f2c2af6488758c5847e694 100644 (file)
@@ -88,11 +88,11 @@ public class BranchDaoIT {
       entry("uuid", "U2"),
       entry("branchType", "BRANCH"),
       entry("kee", "feature/foo"),
-      entry("isMain", true),
       entry("mergeBranchUuid", null),
       entry("pullRequestBinary", null),
       entry("createdAt", 1_000L),
       entry("updatedAt", 1_000L));
+    assertThat(map.get("isMain")).isIn(true, 1L); // Oracle returns 1L instead of true
   }
 
   @Test
index 274ee804fc7cc50395dce67a5b3c25bd2521ac6c..c9deb86a2c64ce5ccbd8b69213e45383b56dff2e 100644 (file)
@@ -90,6 +90,9 @@ public class BranchDao implements Dao {
     return executeLargeInputs(branchKeys, partition -> mapper(dbSession).selectByKeys(projectUuid, branchKeys));
   }
 
+  /*
+   * Returns collection of branches that are in the same project as the component
+   */
   public Collection<BranchDto> selectByComponent(DbSession dbSession, ComponentDto component) {
     String projectUuid = component.getMainBranchProjectUuid();
     if (projectUuid == null) {
index 1aee6960f733cd1cb8c03fa9bf2d6abe3ece8a63..238f99a98e6e454ea924c1be564c3eb85717b582 100644 (file)
@@ -34,7 +34,8 @@ public class UpdateIsMainColumnInProjectBranches extends DataChange {
   protected void execute(Context context) throws SQLException {
     MassUpdate massUpdate = context.prepareMassUpdate();
 
-    massUpdate.select("select uuid, uuid = project_uuid from project_branches");
+    // we need to use case/when/then because Oracle doesn't accept simple solution uuid = project_uuid here
+    massUpdate.select("select uuid, case when uuid = project_uuid then 'true' else 'false' end  from project_branches");
     massUpdate.update("update project_branches set is_main = ? where uuid = ?");
     massUpdate.execute((row, update) -> {
       String uuid = row.getString(1);