.setIsNullable(false)
.setLimit(50)
.build())
+ .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder()
+ .setColumnName("kee_type")
+ .setIsNullable(false)
+ .setLimit(6)
+ .build())
.addColumn(VarcharColumnDef.newVarcharColumnDefBuilder()
.setColumnName("kee")
.setIsNullable(false)
.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)
.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);
}
}
--- /dev/null
+/*
+ * 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());
+ }
+
+}
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;
});
}
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 12);
+ verifyMigrationCount(underTest, 13);
}
}
--- /dev/null
+/*
+ * 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");
+ }
+}
underTest.execute();
- assertProjectBranches(tuple("master", project, project, "LONG", NOW, NOW));
+ assertProjectBranches(tuple("master", project, project, "BRANCH", "LONG", NOW, NOW));
}
@Test
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);
}
db.executeInsert("PROJECT_BRANCHES",
"uuid", uuid,
"project_uuid", uuid,
+ "kee_type", "BRANCH",
"kee", "master",
"branch_type", "LONG",
"created_at", PAST,
--- /dev/null
+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");
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");
+