diff options
author | Janos Gyerik <janos.gyerik@sonarsource.com> | 2019-01-15 10:24:45 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2019-02-11 09:11:46 +0100 |
commit | cde7c00e84577847cfd21b5023a1ddf48029b9c8 (patch) | |
tree | 02f53c83c8cc0802c4aa39b72baf379b4d5aadbd /server/sonar-db-migration | |
parent | f5d0d6237b0e52afcb1981953a7c08baee794915 (diff) | |
download | sonarqube-cde7c00e84577847cfd21b5023a1ddf48029b9c8.tar.gz sonarqube-cde7c00e84577847cfd21b5023a1ddf48029b9c8.zip |
SONAR-11626 Add manual baseline column to project_branches
Diffstat (limited to 'server/sonar-db-migration')
5 files changed, 130 insertions, 3 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/AddManualBaselineToProjectBranches.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/AddManualBaselineToProjectBranches.java new file mode 100644 index 00000000000..3c0ee15e286 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/AddManualBaselineToProjectBranches.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.v77; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.SupportsBlueGreen; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; + +@SupportsBlueGreen +public class AddManualBaselineToProjectBranches extends DdlChange { + + static final String TABLE_NAME = "project_branches"; + + private static final VarcharColumnDef COLUMN_MANUAL_BASELINE_ANALYSIS_UUID = newVarcharColumnDefBuilder() + .setColumnName("manual_baseline_analysis_uuid") + .setIsNullable(true) + .setLimit(UUID_SIZE) + .build(); + + public AddManualBaselineToProjectBranches(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddColumnsBuilder(getDialect(), TABLE_NAME) + .addColumn(COLUMN_MANUAL_BASELINE_ANALYSIS_UUID) + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java index 402538f10be..cadfd7b2314 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java @@ -30,6 +30,9 @@ public class DbVersion77 implements DbVersion { .add(2600, "Drop elasticsearch index 'tests'", DropElasticsearchIndexTests.class) .add(2601, "Delete lines with DATA_TYPE='TEST' from table FILES_SOURCE", DeleteTestDataTypeFromFileSources.class) .add(2602, "Add column LAST_CONNECTION_DATE to USERS table", AddLastConnectionDateToUsers.class) - .add(2603, "Add column LAST_USED_DATE to USER_TOKENS table", AddLastConnectionDateToUserTokens.class); + .add(2603, "Add column LAST_USED_DATE to USER_TOKENS table", AddLastConnectionDateToUserTokens.class) + .add(2604, "Add manual baseline column to PROJECT_BRANCHES", AddManualBaselineToProjectBranches.class) + + ; } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/AddManualBaselineToProjectBranchesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/AddManualBaselineToProjectBranchesTest.java new file mode 100644 index 00000000000..58033be0361 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/AddManualBaselineToProjectBranchesTest.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.v77; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.db.CoreDbTester; + +import static java.sql.Types.VARCHAR; +import static org.sonar.server.platform.db.migration.version.v77.AddManualBaselineToProjectBranches.TABLE_NAME; + +public class AddManualBaselineToProjectBranchesTest { + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(AddManualBaselineToProjectBranchesTest.class, "initial.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private AddManualBaselineToProjectBranches underTest = new AddManualBaselineToProjectBranches(db.database()); + + @Test + public void adds_nullable_columns_to_existing_table() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition(TABLE_NAME, "manual_baseline_analysis_uuid", VARCHAR, 40, true); + } + + @Test + public void migration_is_not_reentrant() throws SQLException { + underTest.execute(); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Fail to execute "); + underTest.execute(); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java index ffd24978cc8..66e9f032d20 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java @@ -30,13 +30,13 @@ public class DbVersion77Test { private DbVersion77 underTest = new DbVersion77(); @Test - public void migrationNumber_starts_at_2500() { + public void migrationNumber_starts_at_2600() { verifyMinimumMigrationNumber(underTest, 2600); } @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 4); + verifyMigrationCount(underTest, 5); } } diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/AddManualBaselineToProjectBranchesTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/AddManualBaselineToProjectBranchesTest/initial.sql new file mode 100644 index 00000000000..2330dcfd9ab --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/AddManualBaselineToProjectBranchesTest/initial.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, + "KEY_TYPE" VARCHAR(12) NOT NULL, + "BRANCH_TYPE" VARCHAR(12), + "MERGE_BRANCH_UUID" VARCHAR(50), + "PULL_REQUEST_BINARY" BLOB, + "CREATED_AT" BIGINT NOT NULL, + "UPDATED_AT" BIGINT NOT NULL, + + CONSTRAINT "PK_PROJECT_BRANCHES" PRIMARY KEY ("UUID") +); +CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE_KEY_TYPE" ON "PROJECT_BRANCHES" ("PROJECT_UUID", "KEE", "KEY_TYPE"); + +INSERT INTO "PROJECT_BRANCHES" VALUES ('foo', 'bar', 'kee', 'BRANCH', 'LONG', NULL, NULL, 0, 0); |