From 4324e6d6325655ccfa50331388cc1fa4d06a533c Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Thu, 15 Jun 2023 09:27:31 -0500 Subject: [PATCH] SONAR-19028 Drop column 'main_branch_project_uuid' in the Components table --- .../step/PersistComponentsStep.java | 17 +----- .../src/main/protobuf/project_dump.proto | 2 +- .../org/sonar/db/purge/PurgeCommandsIT.java | 12 ++--- .../org/sonar/db/component/ComponentDto.java | 30 ----------- .../sonar/db/component/ComponentMapper.xml | 4 -- server/sonar-db-dao/src/schema/schema-sq.ddl | 2 - .../sonar/db/component/ComponentTesting.java | 4 -- .../migration/version/v102/DbVersion102.java | 4 +- .../DropIndexOnMainBranchProjectUuid.java | 32 ++++++++++++ ...DropMainBranchProjectUuidInComponents.java | 32 ++++++++++++ .../DropIndexOnMainBranchProjectUuidTest.java | 51 ++++++++++++++++++ ...MainBranchProjectUuidInComponentsTest.java | 52 +++++++++++++++++++ .../schema.sql | 35 +++++++++++++ .../schema.sql | 34 ++++++++++++ .../server/issue/index/IssueIndexerIT.java | 2 +- .../user/ThreadLocalUserSessionTest.java | 2 +- .../issue/index/IssueIndexFiltersTest.java | 4 +- .../server/component/ws/TreeActionIT.java | 2 +- .../server/duplication/ws/ShowActionIT.java | 2 +- .../server/hotspot/ws/AssignActionIT.java | 4 +- .../hotspot/ws/ChangeStatusActionIT.java | 4 +- .../measure/ws/ComponentTreeActionIT.java | 2 +- 22 files changed, 260 insertions(+), 73 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuid.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponents.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest.java create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest/schema.sql diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java index a4d7aa99540..50b8333a826 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java @@ -97,11 +97,10 @@ public class PersistComponentsStep implements ComputationStep { Map existingDtosByUuids = indexExistingDtosByUuids(dbSession); boolean isRootPrivate = isRootPrivate(treeRootHolder.getRoot(), existingDtosByUuids); - String mainBranchProjectUuid = loadProjectUuidOfMainBranch(); // Insert or update the components in database. They are removed from existingDtosByUuids // at the same time. - new PathAwareCrawler<>(new PersistComponentStepsVisitor(existingDtosByUuids, dbSession, mainBranchProjectUuid)) + new PathAwareCrawler<>(new PersistComponentStepsVisitor(existingDtosByUuids, dbSession)) .visit(treeRootHolder.getRoot()); disableRemainingComponents(dbSession, existingDtosByUuids.values()); @@ -110,14 +109,6 @@ public class PersistComponentsStep implements ComputationStep { } } - @CheckForNull - private String loadProjectUuidOfMainBranch() { - if (!analysisMetadataHolder.getBranch().isMain()) { - return analysisMetadataHolder.getProject().getUuid(); - } - return null; - } - private void disableRemainingComponents(DbSession dbSession, Collection dtos) { Set uuids = dtos.stream() .filter(ComponentDto::isEnabled) @@ -152,10 +143,8 @@ public class PersistComponentsStep implements ComputationStep { private final Map existingComponentDtosByUuids; private final DbSession dbSession; - @Nullable - private final String mainBranchProjectUuid; - PersistComponentStepsVisitor(Map existingComponentDtosByUuids, DbSession dbSession, @Nullable String mainBranchProjectUuid) { + PersistComponentStepsVisitor(Map existingComponentDtosByUuids, DbSession dbSession) { super( CrawlerDepthLimit.LEAVES, PRE_ORDER, @@ -179,7 +168,6 @@ public class PersistComponentsStep implements ComputationStep { }); this.existingComponentDtosByUuids = existingComponentDtosByUuids; this.dbSession = dbSession; - this.mainBranchProjectUuid = mainBranchProjectUuid; } @Override @@ -345,7 +333,6 @@ public class PersistComponentsStep implements ComputationStep { ComponentDto componentDto = new ComponentDto(); componentDto.setUuid(componentUuid); componentDto.setKey(componentKey); - componentDto.setMainBranchProjectUuid(mainBranchProjectUuid); componentDto.setEnabled(true); componentDto.setCreatedAt(new Date(system2.now())); diff --git a/server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto b/server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto index 91a9495631c..d889f946871 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto +++ b/server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto @@ -34,7 +34,7 @@ message Component { reserved 14; // module_uuid_path string deprecated_key = 15; string project_uuid = 16; - reserved 17; + reserved 17; // main_branch_project_uuid } message Branch { diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java index 19c8e65782d..ae98a492771 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java @@ -165,13 +165,11 @@ public class PurgeCommandsIT { dbTester.components().insertComponent(newFileDto(directory1)); dbTester.components().insertComponent(newFileDto(directory2)); - directory1 = dbTester.components().insertComponent(ComponentTesting.newDirectory(branch, "a") - .setMainBranchProjectUuid(project.uuid())); - directory2 = dbTester.components().insertComponent(ComponentTesting.newDirectory(branch, "b") - .setMainBranchProjectUuid(project.uuid())); - dbTester.components().insertComponent(newFileDto(branch, project.uuid()).setMainBranchProjectUuid(project.uuid())); - dbTester.components().insertComponent(newFileDto(directory1).setMainBranchProjectUuid(project.uuid())); - dbTester.components().insertComponent(newFileDto(directory2).setMainBranchProjectUuid(project.uuid())); + directory1 = dbTester.components().insertComponent(ComponentTesting.newDirectory(branch, "a")); + directory2 = dbTester.components().insertComponent(ComponentTesting.newDirectory(branch, "b")); + dbTester.components().insertComponent(newFileDto(branch, project.uuid())); + dbTester.components().insertComponent(newFileDto(directory1)); + dbTester.components().insertComponent(newFileDto(directory2)); underTest.deleteNonMainBranchComponentsByProjectUuid(project.uuid()); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java index 64717fb4a5b..2cf4f9dec67 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java @@ -87,24 +87,6 @@ public class ComponentDto { * - on sub-view: UUID="6" PROJECT_UUID="5" */ private String branchUuid; - - /** - * On non-main branches only, {@link #uuid} of the main branch that represents - * the project ({@link #qualifier}="TRK"). - * It is propagated to all the components of the branch. - * Value is null on the main-branch components and on other kinds of components - * (applications, portfolios). - * Value must be used for loading settings, checking permissions, running webhooks, - * selecting Quality profiles/gates and any other project-related operations. - * Example: - * - project P : kee=P, uuid=U1, qualifier=TRK, project_uuid=U1, main_branch_project_uuid=NULL - * - file F of project P : kee=P:F, uuid=U2, qualifier=FIL, project_uuid=U1, main_branch_project_uuid=NULL - * - branch B of project P : kee=P, uuid=U3, qualifier=TRK, project_uuid=U3, main_branch_project_uuid=U1 - * - file F in branch B of project P : kee=P:F, uuid=U4, qualifier=FIL, project_uuid=U3, main_branch_project_uuid=U1 - */ - @Nullable - private String mainBranchProjectUuid; - private String copyComponentUuid; private String scope; private String qualifier; @@ -244,16 +226,6 @@ public class ComponentDto { return this; } - @Nullable - public String getMainBranchProjectUuid() { - return mainBranchProjectUuid; - } - - public ComponentDto setMainBranchProjectUuid(@Nullable String s) { - this.mainBranchProjectUuid = s; - return this; - } - public boolean isEnabled() { return enabled; } @@ -322,7 +294,6 @@ public class ComponentDto { .append("scope", scope) .append("qualifier", qualifier) .append("branchUuid", branchUuid) - .append("mainBranchProjectUuid", mainBranchProjectUuid) .append("copyComponentUuid", copyComponentUuid) .append("path", path) .append("name", name) @@ -339,7 +310,6 @@ public class ComponentDto { copy.uuid = uuid; copy.uuidPath = uuidPath; copy.branchUuid = branchUuid; - copy.mainBranchProjectUuid = mainBranchProjectUuid; copy.copyComponentUuid = copyComponentUuid; copy.scope = scope; copy.qualifier = qualifier; diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml index da43df99c77..1020644d056 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -6,7 +6,6 @@ p.uuid as uuid, p.uuid_path as uuidPath, p.branch_uuid as branchUuid, - p.main_branch_project_uuid as mainBranchProjectUuid, p.kee as kee, p.name as name, p.long_name as longName, @@ -61,7 +60,6 @@ p.uuid as uuid, p.uuid_path as uuidPath, p.branch_uuid as branchUuid, - p.main_branch_project_uuid as mainBranchProjectUuid, p.kee as kee, case when pr.name is not null and p.scope = 'PRJ' @@ -504,7 +502,6 @@ uuid, uuid_path, branch_uuid, - main_branch_project_uuid, name, long_name, qualifier, @@ -532,7 +529,6 @@ #{uuid,jdbcType=VARCHAR}, #{uuidPath,jdbcType=VARCHAR}, #{branchUuid,jdbcType=VARCHAR}, - #{mainBranchProjectUuid, jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{longName,jdbcType=VARCHAR}, #{qualifier,jdbcType=VARCHAR}, diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 450896f70ec..e66274ae90c 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -216,7 +216,6 @@ CREATE TABLE "COMPONENTS"( "PATH" CHARACTER VARYING(2000), "UUID_PATH" CHARACTER VARYING(1500) NOT NULL, "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL, - "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50), "B_CHANGED" BOOLEAN, "B_NAME" CHARACTER VARYING(500), "B_LONG_NAME" CHARACTER VARYING(500), @@ -230,7 +229,6 @@ CREATE TABLE "COMPONENTS"( "CREATED_AT" TIMESTAMP ); CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST); -CREATE INDEX "IDX_MAIN_BRANCH_PRJ_UUID" ON "COMPONENTS"("MAIN_BRANCH_PROJECT_UUID" NULLS FIRST); CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST); CREATE INDEX "COMPONENTS_BRANCH_UUID" ON "COMPONENTS"("BRANCH_UUID" NULLS FIRST); CREATE UNIQUE INDEX "COMPONENTS_KEE_BRANCH_UUID" ON "COMPONENTS"("KEE" NULLS FIRST, "BRANCH_UUID" NULLS FIRST); diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java index 845d5a1284f..5d301036a6f 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java @@ -66,7 +66,6 @@ public class ComponentTesting { .setLongName(path) .setScope(Scopes.FILE) .setBranchUuid(branch.branchUuid()) - .setMainBranchProjectUuid(mainBranchUuid) .setQualifier(Qualifiers.FILE) .setPath(path) .setCreatedAt(new Date()) @@ -88,7 +87,6 @@ public class ComponentTesting { .setName(path) .setLongName(path) .setBranchUuid(project.branchUuid()) - .setMainBranchProjectUuid(mainBranchUuid) .setPath(path) .setScope(Scopes.DIRECTORY) .setQualifier(Qualifiers.DIRECTORY); @@ -279,7 +277,6 @@ public class ComponentTesting { .setUuidPath(UUID_PATH_OF_ROOT) .setBranchUuid(uuid) .setKey(project.getKey()) - .setMainBranchProjectUuid(project.getUuid()) .setName(project.getName()) .setLongName(project.getName()) .setDescription(project.getDescription()) @@ -299,7 +296,6 @@ public class ComponentTesting { .setUuidPath(UUID_PATH_OF_ROOT) .setBranchUuid(uuid) .setKey(project.getKey()) - .setMainBranchProjectUuid(project.uuid()) .setName(project.name()) .setLongName(project.longName()) .setDescription(project.description()) diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java index 5bf3727a3bc..55331e975c1 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java @@ -59,7 +59,9 @@ public class DbVersion102 implements DbVersion { .add(10_2_011, "Create index 'ce_queue_entity_uuid' in 'ce_queue' table", CreateIndexEntityUuidInCeQueue.class) .add(10_2_012, "Drop 'project_mappings' table", DropTableProjectMappings.class) + + .add(10_2_013, "Drop index on 'components.main_branch_project_uuid", DropIndexOnMainBranchProjectUuid.class) + .add(10_2_014, "Drop column 'main_branch_project_uuid' in the components table", DropMainBranchProjectUuidInComponents.class) ; } - } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuid.java new file mode 100644 index 00000000000..4e57b01746a --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuid.java @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropIndexChange; + +public class DropIndexOnMainBranchProjectUuid extends DropIndexChange { + private static final String INDEX_NAME = "idx_main_branch_prj_uuid"; + private static final String TABLE_NAME = "components"; + + public DropIndexOnMainBranchProjectUuid(Database db) { + super(db, INDEX_NAME, TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponents.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponents.java new file mode 100644 index 00000000000..3078b6bf61e --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponents.java @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropColumnChange; + +class DropMainBranchProjectUuidInComponents extends DropColumnChange { + static final String TABLE_NAME = "components"; + static final String COLUMN_NAME = "main_branch_project_uuid"; + + public DropMainBranchProjectUuidInComponents(Database db) { + super(db, TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest.java new file mode 100644 index 00000000000..8a46809324c --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +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; + +public class DropIndexOnMainBranchProjectUuidTest { + private static final String TABLE_NAME = "components"; + private static final String COLUMN_NAME = "main_branch_project_uuid"; + private static final String INDEX_NAME = "idx_main_branch_prj_uuid"; + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnMainBranchProjectUuidTest.class, "schema.sql"); + private final DdlChange underTest = new DropIndexOnMainBranchProjectUuid(db.database()); + + @Test + public void drops_index() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + underTest.execute(); + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest.java new file mode 100644 index 00000000000..f02681814dc --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import java.sql.Types; +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.sonar.server.platform.db.migration.version.v102.DropMainBranchProjectUuidInComponents.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v102.DropMainBranchProjectUuidInComponents.TABLE_NAME; + +public class DropMainBranchProjectUuidInComponentsTest { + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(DropMainBranchProjectUuidInComponentsTest.class, "schema.sql"); + private final DdlChange underTest = new DropMainBranchProjectUuidInComponents(db.database()); + + @Test + public void drops_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); + underTest.execute(); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest/schema.sql new file mode 100644 index 00000000000..e56d84cbc0d --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest/schema.sql @@ -0,0 +1,35 @@ + +CREATE TABLE "COMPONENTS"( + "UUID" CHARACTER VARYING(50) NOT NULL, + "KEE" CHARACTER VARYING(1000), + "DEPRECATED_KEE" CHARACTER VARYING(400), + "NAME" CHARACTER VARYING(2000), + "LONG_NAME" CHARACTER VARYING(2000), + "DESCRIPTION" CHARACTER VARYING(2000), + "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL, + "SCOPE" CHARACTER VARYING(3), + "QUALIFIER" CHARACTER VARYING(10), + "PRIVATE" BOOLEAN NOT NULL, + "LANGUAGE" CHARACTER VARYING(20), + "COPY_COMPONENT_UUID" CHARACTER VARYING(50), + "PATH" CHARACTER VARYING(2000), + "UUID_PATH" CHARACTER VARYING(1500) NOT NULL, + "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL, + "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50), + "B_CHANGED" BOOLEAN, + "B_NAME" CHARACTER VARYING(500), + "B_LONG_NAME" CHARACTER VARYING(500), + "B_DESCRIPTION" CHARACTER VARYING(2000), + "B_ENABLED" BOOLEAN, + "B_QUALIFIER" CHARACTER VARYING(10), + "B_LANGUAGE" CHARACTER VARYING(20), + "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50), + "B_PATH" CHARACTER VARYING(2000), + "B_UUID_PATH" CHARACTER VARYING(1500), + "CREATED_AT" TIMESTAMP +); +CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST); +CREATE INDEX "IDX_MAIN_BRANCH_PRJ_UUID" ON "COMPONENTS"("MAIN_BRANCH_PROJECT_UUID" NULLS FIRST); +CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST); +CREATE INDEX "COMPONENTS_BRANCH_UUID" ON "COMPONENTS"("BRANCH_UUID" NULLS FIRST); +CREATE UNIQUE INDEX "COMPONENTS_KEE_BRANCH_UUID" ON "COMPONENTS"("KEE" NULLS FIRST, "BRANCH_UUID" NULLS FIRST); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest/schema.sql new file mode 100644 index 00000000000..516b2ad1679 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest/schema.sql @@ -0,0 +1,34 @@ + +CREATE TABLE "COMPONENTS"( + "UUID" CHARACTER VARYING(50) NOT NULL, + "KEE" CHARACTER VARYING(1000), + "DEPRECATED_KEE" CHARACTER VARYING(400), + "NAME" CHARACTER VARYING(2000), + "LONG_NAME" CHARACTER VARYING(2000), + "DESCRIPTION" CHARACTER VARYING(2000), + "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL, + "SCOPE" CHARACTER VARYING(3), + "QUALIFIER" CHARACTER VARYING(10), + "PRIVATE" BOOLEAN NOT NULL, + "LANGUAGE" CHARACTER VARYING(20), + "COPY_COMPONENT_UUID" CHARACTER VARYING(50), + "PATH" CHARACTER VARYING(2000), + "UUID_PATH" CHARACTER VARYING(1500) NOT NULL, + "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL, + "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50), + "B_CHANGED" BOOLEAN, + "B_NAME" CHARACTER VARYING(500), + "B_LONG_NAME" CHARACTER VARYING(500), + "B_DESCRIPTION" CHARACTER VARYING(2000), + "B_ENABLED" BOOLEAN, + "B_QUALIFIER" CHARACTER VARYING(10), + "B_LANGUAGE" CHARACTER VARYING(20), + "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50), + "B_PATH" CHARACTER VARYING(2000), + "B_UUID_PATH" CHARACTER VARYING(1500), + "CREATED_AT" TIMESTAMP +); +CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST); +CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST); +CREATE INDEX "COMPONENTS_BRANCH_UUID" ON "COMPONENTS"("BRANCH_UUID" NULLS FIRST); +CREATE UNIQUE INDEX "COMPONENTS_KEE_BRANCH_UUID" ON "COMPONENTS"("KEE" NULLS FIRST, "BRANCH_UUID" NULLS FIRST); diff --git a/server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java b/server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java index 6a131ee875e..fd1e8d5d23c 100644 --- a/server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java +++ b/server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java @@ -483,7 +483,7 @@ public class IssueIndexerIT { ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature/foo")); BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), branch.uuid()).orElseThrow(); ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(branch, "src/main/java/foo")); - ComponentDto file = db.components().insertComponent(newFileDto(branch, dir, "F1").setMainBranchProjectUuid(project.uuid())); + ComponentDto file = db.components().insertComponent(newFileDto(branch, dir, "F1")); IssueDto issue = db.issues().insert(rule, branch, file); underTest.indexAllIssues(); diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java index db58d6bdeef..0771d7b1e6a 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java @@ -106,7 +106,7 @@ public class ThreadLocalUserSessionTest { .setGroups(group); threadLocalUserSession.set(expected); - ComponentDto componentDto = new ComponentDto().setQualifier(Qualifiers.APP).setMainBranchProjectUuid("component-uuid"); + ComponentDto componentDto = new ComponentDto().setQualifier(Qualifiers.APP); ProjectDto projectDto = new ProjectDto().setQualifier(Qualifiers.APP).setUuid("project-uuid"); assertThatThrownBy(() -> threadLocalUserSession.checkChildProjectsPermission(USER, componentDto)) .isInstanceOf(ForbiddenException.class); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java index 90731021766..9c6f173365f 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java @@ -209,7 +209,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon { ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); - ComponentDto branchFile = db.components().insertComponent(newFileDto(branch, project.uuid())).setMainBranchProjectUuid(project.uuid()); + ComponentDto branchFile = db.components().insertComponent(newFileDto(branch, project.uuid())); indexIssues( newDocForProject("I1", project), @@ -308,7 +308,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon { ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch2")); ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("prj1")).getMainBranchComponent(); ComponentDto project1Branch1 = db.components().insertProjectBranch(project1); - ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1)).setMainBranchProjectUuid(project1.uuid()); + ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1)); ComponentDto project1Branch2 = db.components().insertProjectBranch(project1); ComponentDto project2 = db.components().insertPrivateProject(p -> p.setKey("prj2")).getMainBranchComponent(); indexView(applicationBranch1.uuid(), asList(project1Branch1.uuid(), project2.uuid())); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java index 3d91ecee72f..40d09c15a4f 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java @@ -319,7 +319,7 @@ public class TreeActionIT { ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("project-key")).getMainBranchComponent(); ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey(projectBranchName)); ComponentDto techProjectBranch = db.components().insertComponent(newProjectCopy(projectBranch, applicationBranch) - .setKey(applicationBranch.getKey() + project.getKey()).setMainBranchProjectUuid(application.getUuid())); + .setKey(applicationBranch.getKey() + project.getKey())); logInWithBrowsePermission(applicationData); userSession.addProjectBranchMapping(application.getUuid(), applicationBranch); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java index 70841845c43..cb879dfd0a3 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java @@ -110,7 +110,7 @@ public class ShowActionIT { String branchName = randomAlphanumeric(248); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName)); userSessionRule.addProjectBranchMapping(project.uuid(), branch); - ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()).setMainBranchProjectUuid(project.uuid())); + ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid())); db.measures().insertLiveMeasure(file, dataMetric, m -> m.setData(format("\n" + " \n" + " \n" + diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/AssignActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/AssignActionIT.java index 81a4677452c..950326e7cfd 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/AssignActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/AssignActionIT.java @@ -356,10 +356,12 @@ public class AssignActionIT { UserDto assignee = insertUser(randomAlphanumeric(15)); when(branchDto.getBranchType()).thenReturn(BranchType.BRANCH); + String projectUuid = "projectUuid"; + when(branchDto.getProjectUuid()).thenReturn(projectUuid); when(issueFieldsSetter.assign(eq(hotspot.toDefaultIssue()), userMatcher(assignee), any(IssueChangeContext.class))).thenReturn(true); executeRequest(hotspot, assignee.getLogin(), null); - verify(hotspotChangeEventService).distributeHotspotChangedEvent(eq(project.getMainBranchProjectUuid()), any(HotspotChangedEvent.class)); + verify(hotspotChangeEventService).distributeHotspotChangedEvent(eq(projectUuid), any(HotspotChangedEvent.class)); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ChangeStatusActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ChangeStatusActionIT.java index 1d1def56ee8..4d6841bc393 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ChangeStatusActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ChangeStatusActionIT.java @@ -463,12 +463,14 @@ public class ChangeStatusActionIT { .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto()); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); when(branchDto.getBranchType()).thenReturn(BranchType.BRANCH); + String projectUuid = "projectUuid"; + when(branchDto.getProjectUuid()).thenReturn(projectUuid); IssueDto hotspot = dbTester.issues().insertHotspot(project, file); when(transitionService.doTransition(any(), any(), any())).thenReturn(true); newRequest(hotspot, STATUS_REVIEWED, RESOLUTION_FIXED, NO_COMMENT).execute(); - verify(hotspotChangeEventService).distributeHotspotChangedEvent(eq(project.getMainBranchProjectUuid()), any(HotspotChangedEvent.class)); + verify(hotspotChangeEventService).distributeHotspotChangedEvent(eq(projectUuid), any(HotspotChangedEvent.class)); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java index 5781e8bf7e5..a80aa615214 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java @@ -611,7 +611,7 @@ public class ComponentTreeActionIT { ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST)); userSession.addProjectBranchMapping(projectData.projectUuid(), branch); SnapshotDto analysis = db.components().insertSnapshot(branch); - ComponentDto file = db.components().insertComponent(newFileDto(branch, mainBranch.uuid()).setMainBranchProjectUuid(mainBranch.uuid())); + ComponentDto file = db.components().insertComponent(newFileDto(branch, mainBranch.uuid())); MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name())); LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d)); -- 2.39.5