]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19028 Drop column 'main_branch_project_uuid' in the Components table
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 15 Jun 2023 14:27:31 +0000 (09:27 -0500)
committersonartech <sonartech@sonarsource.com>
Tue, 20 Jun 2023 15:13:44 +0000 (15:13 +0000)
22 files changed:
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuid.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponents.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest/schema.sql [new file with mode: 0644]
server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIndexerIT.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/AssignActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ChangeStatusActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java

index a4d7aa995405603bc73bf32e7edb9fc51fbbeafd..50b8333a8269e9a3774ab04c90aeba7a4d29ec2c 100644 (file)
@@ -97,11 +97,10 @@ public class PersistComponentsStep implements ComputationStep {
 
       Map<String, ComponentDto> 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<ComponentDto> dtos) {
     Set<String> uuids = dtos.stream()
       .filter(ComponentDto::isEnabled)
@@ -152,10 +143,8 @@ public class PersistComponentsStep implements ComputationStep {
 
     private final Map<String, ComponentDto> existingComponentDtosByUuids;
     private final DbSession dbSession;
-    @Nullable
-    private final String mainBranchProjectUuid;
 
-    PersistComponentStepsVisitor(Map<String, ComponentDto> existingComponentDtosByUuids, DbSession dbSession, @Nullable String mainBranchProjectUuid) {
+    PersistComponentStepsVisitor(Map<String, ComponentDto> 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()));
 
index 91a9495631cb704e89246ab35c5436d36b84c17a..d889f946871cac24580ace6528debde631093a02 100644 (file)
@@ -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 {
index 19c8e65782d2a015766245928cc3888858475074..ae98a492771e1c13273916f4175e119ee697af43 100644 (file)
@@ -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());
 
index 64717fb4a5b26d053534aa8a15796548246a90fe..2cf4f9dec67c3e0558172ae7d6ff4fc7e1446b3e 100644 (file)
@@ -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;
index da43df99c778de68a296ce9a08976b1d1181cfaa..1020644d056ed983d9df07ceadfde810da2e4b13 100644 (file)
@@ -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'
       uuid,
       uuid_path,
       branch_uuid,
-      main_branch_project_uuid,
       name,
       long_name,
       qualifier,
     #{uuid,jdbcType=VARCHAR},
     #{uuidPath,jdbcType=VARCHAR},
     #{branchUuid,jdbcType=VARCHAR},
-    #{mainBranchProjectUuid, jdbcType=VARCHAR},
     #{name,jdbcType=VARCHAR},
     #{longName,jdbcType=VARCHAR},
     #{qualifier,jdbcType=VARCHAR},
index 450896f70ec98d7cfa17bf4ca940b94a77e43e38..e66274ae90c96ba82b8c0ffd0a574d2ea314ea4b 100644 (file)
@@ -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);
index 845d5a1284fa0761c8734f89df8443fc5cf05784..5d301036a6fde93849176b10a763aa8159c4151e 100644 (file)
@@ -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())
index 5bf3727a3bcfff7e22a0347acaa33f86f408b698..55331e975c1995ad587b9b036f62cceea0a3294b 100644 (file)
@@ -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 (file)
index 0000000..4e57b01
--- /dev/null
@@ -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 (file)
index 0000000..3078b6b
--- /dev/null
@@ -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 (file)
index 0000000..8a46809
--- /dev/null
@@ -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 (file)
index 0000000..f026818
--- /dev/null
@@ -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 (file)
index 0000000..e56d84c
--- /dev/null
@@ -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 (file)
index 0000000..516b2ad
--- /dev/null
@@ -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);
index 6a131ee875eadabf7d1428a8dbb529e475549339..fd1e8d5d23c4b50fc2f246aab3690875637a8e91 100644 (file)
@@ -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();
index db58d6bdeefd76d9223b5dec4fbe74aa1cab12dd..0771d7b1e6a5dd8bddb49c524eae8f1446a17e92 100644 (file)
@@ -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);
index 9073102176659b8f8e06366059df1726fa252bce..9c6f173365f698c4fef0a34c9b78c9afd8945583 100644 (file)
@@ -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()));
index 3d91ecee72f1a204b1d92cc6d8cf4471f46b4092..40d09c15a4f70e7b8eccf0190933c29d9d526eb9 100644 (file)
@@ -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);
index 70841845c434479dbc89f3931a6bce7d4ad51410..cb879dfd0a3770ab91c3eeb6c44f7387183f9706 100644 (file)
@@ -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("<duplications>\n" +
       "  <g>\n" +
       "    <b s=\"31\" l=\"5\" r=\"%s\"/>\n" +
index 81a4677452c7f00548f59c7ec422a220b2a0d56a..950326e7cfd02af09f8009a6a528a5412b12f833 100644 (file)
@@ -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
index 1d1def56ee8ef28e02f3e60f6feaa69cef0c4a41..4d6841bc393696f666e7a18c451626f6fc6a4c30 100644 (file)
@@ -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
index 5781e8bf7e5cbc9878466b246513aea716c5752f..a80aa6152142072771d0ec3e6ccc08b76d0f9a87 100644 (file)
@@ -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));