diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-10-28 12:07:23 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-11-09 20:03:15 +0000 |
commit | e8905886d0e77cc080022dff7e0df79e4823e5de (patch) | |
tree | 899ad2f2961d3de1070605ceb66b8e69ef4aa222 /server/sonar-db-migration | |
parent | 2dd9ce1a7271e6448e546d21eb59a2ac41127c08 (diff) | |
download | sonarqube-e8905886d0e77cc080022dff7e0df79e4823e5de.tar.gz sonarqube-e8905886d0e77cc080022dff7e0df79e4823e5de.zip |
SONAR-15498 Compute manually selected projects in portfolio
Diffstat (limited to 'server/sonar-db-migration')
6 files changed, 149 insertions, 4 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/AddBranchToPortfolios.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/AddBranchToPortfolios.java index e546d9f4b6b..e9697c41a88 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/AddBranchToPortfolios.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/AddBranchToPortfolios.java @@ -29,7 +29,7 @@ import org.sonar.server.platform.db.migration.step.DdlChange; public class AddBranchToPortfolios extends DdlChange { private static final String TABLE_NAME = "portfolios"; - private static final String COLUMN_NAME = "branch_name"; + private static final String COLUMN_NAME = "branch_key"; public AddBranchToPortfolios(Database db) { super(db); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/AlterKeeInComponentsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/AlterKeeInComponentsTable.java new file mode 100644 index 00000000000..be802b6087a --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/AlterKeeInComponentsTable.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 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.v92; + +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.AlterColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class AlterKeeInComponentsTable extends DdlChange { + private static final String TABLE = "components"; + + private static final VarcharColumnDef columnDefinition = newVarcharColumnDefBuilder() + .setColumnName("kee") + .setIsNullable(true) + .setLimit(1000) + .build(); + + public AlterKeeInComponentsTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AlterColumnsBuilder(getDialect(), TABLE) + .updateColumn(columnDefinition) + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java index 9eb256422a0..778bea48082 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java @@ -33,8 +33,10 @@ public class DbVersion92 implements DbVersion { .add(6105, "Create qgate_group_permissions Table", CreateQGateGroupPermissionsTable.class) .add(6106, "Create column sonarlint_ad_seen in 'users'", AddSonarlintAdSeenColumnInUsersTable.class) .add(6107, "Upsert value of sonarlint_ad_seen in 'users'", UpsertSonarlintAdSeenValue.class) - .add(6108, "Create table 'portfolio_proj_branches'", CreatePortfolioProjectBranchesTable.class) - .add(6109, "Add column 'branch_name' to table 'portfolios'", AddBranchToPortfolios.class) + .add(6108, "Change size of column 'kee' in 'components'", AlterKeeInComponentsTable.class) + .add(6109, "Create table 'portfolio_proj_branches'", CreatePortfolioProjectBranchesTable.class) + .add(6110, "Add column 'branch_key' to table 'portfolios'", AddBranchToPortfolios.class) + .add(6111, "Change size of column 'kee' in 'components'", AlterKeeInComponentsTable.class) ; } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/AddBranchToPortfoliosTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/AddBranchToPortfoliosTest.java index 9952f7f2fe0..da47fe6e09f 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/AddBranchToPortfoliosTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/AddBranchToPortfoliosTest.java @@ -27,7 +27,7 @@ import org.sonar.db.CoreDbTester; public class AddBranchToPortfoliosTest { private static final String TABLE_NAME = "portfolios"; - private static final String COLUMN_NAME = "branch_name"; + private static final String COLUMN_NAME = "branch_key"; @Rule public final CoreDbTester db = CoreDbTester.createForSchema(AddBranchToPortfoliosTest.class, "schema.sql"); diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/AlterKeeInComponentsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/AlterKeeInComponentsTableTest.java new file mode 100644 index 00000000000..b7b973ed825 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/AlterKeeInComponentsTableTest.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 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.v92; + +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.DdlChange; + +import static java.sql.Types.VARCHAR; + +public class AlterKeeInComponentsTableTest { + private final String TABLE = "components"; + private final String COLUMN = "kee"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AlterKeeInComponentsTableTest.class, "schema.sql"); + + private final DdlChange underTest = new AlterKeeInComponentsTable(db.database()); + + @Test + public void selection_expression_column_is_altered() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition(TABLE, COLUMN, VARCHAR, 1000, true); + } + + @Test + public void migration_is_reentrant() throws SQLException { + underTest.execute(); + underTest.execute(); + + db.assertColumnDefinition(TABLE, COLUMN, VARCHAR, 1000, true); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v92/AlterKeeInComponentsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v92/AlterKeeInComponentsTableTest/schema.sql new file mode 100644 index 00000000000..520824c5490 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v92/AlterKeeInComponentsTableTest/schema.sql @@ -0,0 +1,41 @@ +CREATE TABLE "COMPONENTS"( + "UUID" VARCHAR(50) NOT NULL, + "KEE" VARCHAR(400), + "DEPRECATED_KEE" VARCHAR(400), + "NAME" VARCHAR(2000), + "LONG_NAME" VARCHAR(2000), + "DESCRIPTION" VARCHAR(2000), + "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL, + "SCOPE" VARCHAR(3), + "QUALIFIER" VARCHAR(10), + "PRIVATE" BOOLEAN NOT NULL, + "ROOT_UUID" VARCHAR(50) NOT NULL, + "LANGUAGE" VARCHAR(20), + "COPY_COMPONENT_UUID" VARCHAR(50), + "PATH" VARCHAR(2000), + "UUID_PATH" VARCHAR(1500) NOT NULL, + "PROJECT_UUID" VARCHAR(50) NOT NULL, + "MODULE_UUID" VARCHAR(50), + "MODULE_UUID_PATH" VARCHAR(1500), + "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50), + "B_CHANGED" BOOLEAN, + "B_NAME" VARCHAR(500), + "B_LONG_NAME" VARCHAR(500), + "B_DESCRIPTION" VARCHAR(2000), + "B_ENABLED" BOOLEAN, + "B_QUALIFIER" VARCHAR(10), + "B_LANGUAGE" VARCHAR(20), + "B_COPY_COMPONENT_UUID" VARCHAR(50), + "B_PATH" VARCHAR(2000), + "B_UUID_PATH" VARCHAR(1500), + "B_MODULE_UUID" VARCHAR(50), + "B_MODULE_UUID_PATH" VARCHAR(1500), + "CREATED_AT" TIMESTAMP +); +CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE"); +CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID"); +CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID"); +CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER"); +CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID"); +CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID"); +CREATE INDEX "IDX_MAIN_BRANCH_PRJ_UUID" ON "COMPONENTS"("MAIN_BRANCH_PROJECT_UUID"); |