diff options
author | Jacek <jacek.poreda@sonarsource.com> | 2020-05-29 15:11:50 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-06-26 20:04:56 +0000 |
commit | 9b49b87d256933a17e864220fd070296fd2366fc (patch) | |
tree | f2df2f6003e4c989d26ae1dbe4ead09a0c27a8ed /server/sonar-db-migration | |
parent | 88131a33e07fe611f32883079614d1e768f60076 (diff) | |
download | sonarqube-9b49b87d256933a17e864220fd070296fd2366fc.tar.gz sonarqube-9b49b87d256933a17e864220fd070296fd2366fc.zip |
SONAR-13444 add 'need_issue_sync' to 'project_branches' table
Diffstat (limited to 'server/sonar-db-migration')
11 files changed, 365 insertions, 1 deletions
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 index 00000000000..e43845bedb9 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSync.java @@ -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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java index af5f746ee8e..490e434c402 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java @@ -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 index 00000000000..f4603a811ab --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNull.java @@ -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 index 00000000000..f2810cc2dac --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSync.java @@ -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; + }); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java index 55d36072a29..e298cf83538 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java @@ -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 index 00000000000..dd7aa733dbf --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSyncTest.java @@ -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 index 00000000000..5066e588447 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNullTest.java @@ -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 index 00000000000..6a36bed84a3 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSyncTest.java @@ -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 index 00000000000..04995e9560f --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/AddProjectBranchesNeedIssueSyncTest/schema.sql @@ -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 index 00000000000..de231f6b163 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/MakeProjectBranchesNeedIssueSyncNonNullTest/schema.sql @@ -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 index 00000000000..de231f6b163 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/PopulateProjectBranchesNeedIssueSyncTest/schema.sql @@ -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"); |