]> source.dussan.org Git - sonarqube.git/commitdiff
Migrate drop of PR columns for Next
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 4 Oct 2017 08:18:35 +0000 (10:18 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 4 Oct 2017 10:13:25 +0000 (12:13 +0200)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableProjectBranches.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DropPrColumnsFromProjectBranches.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranches.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DropPrColumnsFromProjectBranchesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranchesTest.java
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/DropPrColumnsFromProjectBranchesTest/initial.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/PopulateMainProjectBranchesTest/initial.sql

index 072e2cf428b414d32064663f24d92150fe67b416..db40d988aecf4caf8b7747f371178e612325429d 100644 (file)
@@ -47,6 +47,11 @@ 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)
@@ -62,6 +67,11 @@ 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)
index bc9c28859d1a01fba4ef09cdc39c151cdb035ba4..bbaf6c984bf981fab8dbdecb26b11d7aef97063f 100644 (file)
@@ -39,6 +39,6 @@ public class DbVersion66 implements DbVersion {
       .add(1810, "Add ce_activity.error_type", AddErrorTypeColumnToCeActivityTable.class)
       .add(1811, "Create table qprofile_edit_users", CreateTableQProfileEditUsers.class)
       .add(1812, "Create table qprofile_edit_groups", CreateTableQProfileEditGroups.class)
-    ;
+      .add(1813, "Drop PR columns from project_brances", DropPrColumnsFromProjectBranches.class);
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DropPrColumnsFromProjectBranches.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DropPrColumnsFromProjectBranches.java
new file mode 100644 (file)
index 0000000..d8a62e1
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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.server.platform.db.migration.version.v66;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+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 DropPrColumnsFromProjectBranches extends DdlChange {
+  static final String PROJECT_BRANCHES_TABLE_NAME = "project_branches";
+
+  public DropPrColumnsFromProjectBranches(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new DropIndexBuilder(getDialect()).setTable(PROJECT_BRANCHES_TABLE_NAME).setName("project_branches_kee").build());
+    context.execute(new DropColumnsBuilder(getDialect(), PROJECT_BRANCHES_TABLE_NAME, "kee_type", "pull_request_title").build());
+    context.execute(
+      new CreateIndexBuilder(getDialect())
+        .setTable(PROJECT_BRANCHES_TABLE_NAME)
+        .setName("project_branches_kee")
+        .setUnique(true)
+        .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder()
+          .setColumnName("project_uuid")
+          .setIsNullable(false)
+          .setLimit(50)
+          .build())
+        .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder()
+          .setColumnName("kee")
+          .setIsNullable(false)
+          .setLimit(255)
+          .build())
+        .build());
+  }
+
+}
index 77fca273828077030bbdc918bae7b9bc2d97ce3c..9d66de5abdca307411527e526a72e59b355cc4b0 100644 (file)
@@ -43,18 +43,20 @@ 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, branch_type, "
-      + "merge_branch_uuid, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)");
+    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.rowPluralName("projects");
     massUpdate.execute((row, update) -> {
       String uuid = row.getString(1);
       update.setString(1, uuid);
       update.setString(2, uuid);
-      update.setString(3, MAIN_BRANCH_NAME);
-      update.setString(4, "LONG");
-      update.setString(5, null);
-      update.setLong(6, now);
-      update.setLong(7, now);
+      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);
       return true;
     });
   }
index d249593f897e21aebd449e879f67e8380bbb9341..de7450360cfbb85e98a3f3c1c783074f6043be0c 100644 (file)
@@ -36,7 +36,7 @@ public class DbVersion66Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 12);
+    verifyMigrationCount(underTest, 13);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DropPrColumnsFromProjectBranchesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DropPrColumnsFromProjectBranchesTest.java
new file mode 100644 (file)
index 0000000..8d71727
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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.server.platform.db.migration.version.v66;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.sonar.server.platform.db.migration.version.v66.DropPrColumnsFromProjectBranches.PROJECT_BRANCHES_TABLE_NAME;
+
+public class DropPrColumnsFromProjectBranchesTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropPrColumnsFromProjectBranchesTest.class, "initial.sql");
+
+  private DropPrColumnsFromProjectBranches underTest = new DropPrColumnsFromProjectBranches(db.database());
+
+  @Test
+  public void drop_columns() throws SQLException {
+    underTest.execute();
+    db.assertColumnDoesNotExist(PROJECT_BRANCHES_TABLE_NAME, "kee_type");
+    db.assertColumnDoesNotExist(PROJECT_BRANCHES_TABLE_NAME, "pull_request_title");
+    db.assertUniqueIndex(PROJECT_BRANCHES_TABLE_NAME, "project_branches_kee", "project_uuid", "kee");
+  }
+}
index e9a10caa2d82975f65740efb83909b36e39c7a84..29433a7dc19d18095ab49660c8da7d6e1b7cda95 100644 (file)
@@ -54,7 +54,7 @@ public class PopulateMainProjectBranchesTest {
 
     underTest.execute();
 
-    assertProjectBranches(tuple("master", project, project, "LONG", NOW, NOW));
+    assertProjectBranches(tuple("master", project, project, "BRANCH", "LONG", NOW, NOW));
   }
 
   @Test
@@ -81,13 +81,13 @@ public class PopulateMainProjectBranchesTest {
 
     underTest.execute();
 
-    assertProjectBranches(tuple("master", project, project, "LONG", PAST, PAST));
+    assertProjectBranches(tuple("master", project, project, "BRANCH", "LONG", PAST, PAST));
   }
 
   private void assertProjectBranches(Tuple... expectedTuples) {
-    assertThat(db.select("SELECT KEE, UUID, PROJECT_UUID, BRANCH_TYPE, CREATED_AT, UPDATED_AT FROM PROJECT_BRANCHES")
+    assertThat(db.select("SELECT KEE, UUID, PROJECT_UUID, KEE_TYPE, 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("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("KEE_TYPE"), map.get("BRANCH_TYPE"), map.get("CREATED_AT"), map.get("UPDATED_AT")))
       .collect(Collectors.toList()))
         .containsExactlyInAnyOrder(expectedTuples);
   }
@@ -116,6 +116,7 @@ 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/DropPrColumnsFromProjectBranchesTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/DropPrColumnsFromProjectBranchesTest/initial.sql
new file mode 100644 (file)
index 0000000..ceb803e
--- /dev/null
@@ -0,0 +1,13 @@
+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");
index 7ae1777df165c4556972f31d4a79654359947845..700b809073b2a3e9c9b887eadd38742b0fb1292d 100644 (file)
@@ -48,11 +48,14 @@ 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");
+CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE" ON "PROJECT_BRANCHES" ("PROJECT_UUID", "KEE_TYPE", "KEE");
+