From: Duarte Meneses Date: Wed, 4 Oct 2017 08:18:35 +0000 (+0200) Subject: Migrate drop of PR columns for Next X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F2607%2Fhead;p=sonarqube.git Migrate drop of PR columns for Next --- 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 072e2cf428b..db40d988aec 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,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) diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java index bc9c28859d1..bbaf6c984bf 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java @@ -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 index 00000000000..d8a62e10048 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DropPrColumnsFromProjectBranches.java @@ -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()); + } + +} 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 77fca273828..9d66de5abdc 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,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; }); } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java index d249593f897..de7450360cf 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java @@ -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 index 00000000000..8d71727808c --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DropPrColumnsFromProjectBranchesTest.java @@ -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"); + } +} 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 e9a10caa2d8..29433a7dc19 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, "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 index 00000000000..ceb803e9e84 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/DropPrColumnsFromProjectBranchesTest/initial.sql @@ -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"); 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 7ae1777df16..700b809073b 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,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"); +