]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15398 Project is not removed from application_projects table when deleted
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 15 Nov 2021 21:42:14 +0000 (15:42 -0600)
committersonartech <sonartech@sonarsource.com>
Thu, 18 Nov 2021 20:03:33 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java

index c16a1741dd9a4354f2babc037eb6725114556c05..64139dbb480c9ddba3c6b624349b7b7c0f4018c0 100644 (file)
@@ -402,17 +402,25 @@ class PurgeCommands {
     profiler.stop();
   }
 
+  void deleteApplicationProjectsByProject(String projectUuid) {
+    profiler.start("deleteApplicationProjectsByProject (app_projects)");
+    purgeMapper.deleteAppBranchProjectBranchesByProjectUuid(projectUuid);
+    purgeMapper.deleteAppProjectsByProjectUuid(projectUuid);
+    session.commit();
+    profiler.stop();
+  }
+
   void deleteApplicationProjects(String applicationUuid) {
     profiler.start("deleteApplicationProjects (app_projects)");
-    purgeMapper.deleteApplicationBranchProjectBranchesByApplicationUuid(applicationUuid);
-    purgeMapper.deleteApplicationProjectsByApplicationUuid(applicationUuid);
+    purgeMapper.deleteAppBranchProjectBranchesByAppUuid(applicationUuid);
+    purgeMapper.deleteAppProjectsByAppUuid(applicationUuid);
     session.commit();
     profiler.stop();
   }
 
   void deleteApplicationBranchProjects(String applicationBranchUuid) {
     profiler.start("deleteApplicationBranchProjects (app_branch_project_branch)");
-    purgeMapper.deleteApplicationBranchProjects(applicationBranchUuid);
+    purgeMapper.deleteAppBranchProjectsByAppBranchUuid(applicationBranchUuid);
     session.commit();
     profiler.stop();
   }
@@ -433,7 +441,7 @@ class PurgeCommands {
 
   void deleteBranch(String rootUuid) {
     profiler.start("deleteBranch (project_branches)");
-    purgeMapper.deleteApplicationBranchProjectBranchesByProjectBranchUuid(rootUuid);
+    purgeMapper.deleteAppBranchProjectBranchesByProjectBranchUuid(rootUuid);
     purgeMapper.deleteBranchByUuid(rootUuid);
     session.commit();
     profiler.stop();
index f86fa31d477ff68b16a7c3bf9f49af5f44f7df67..21211047e58fff5a08e3bed46d4b6abb58ea8ae0 100644 (file)
@@ -232,6 +232,7 @@ public class PurgeDao implements Dao {
     commands.deleteBranch(rootUuid);
     commands.deleteApplicationBranchProjects(rootUuid);
     commands.deleteApplicationProjects(rootUuid);
+    commands.deleteApplicationProjectsByProject(rootUuid);
     commands.deleteProjectInPortfolios(rootUuid);
     commands.deleteComponents(rootUuid);
     commands.deleteComponentsByMainBranchProjectUuid(rootUuid);
index f88c7e6dcdaa73365cf25cf5d3196f21d7f21f02..eb9ba4d01d6cf6f292bd5dcfe9bae0a758f1297d 100644 (file)
@@ -139,13 +139,17 @@ public interface PurgeMapper {
 
   void deleteProjectMappingsByProjectUuid(@Param("projectUuid") String projectUuid);
 
-  void deleteApplicationProjectsByApplicationUuid(@Param("applicationUuid") String applicationUuid);
+  void deleteAppProjectsByAppUuid(@Param("applicationUuid") String applicationUuid);
 
-  void deleteApplicationBranchProjectBranchesByApplicationUuid(@Param("applicationUuid") String applicationUuid);
+  void deleteAppProjectsByProjectUuid(@Param("projectUuid") String projectUuid);
 
-  void deleteApplicationBranchProjects(@Param("branchUuid") String applicationBranchUuid);
+  void deleteAppBranchProjectBranchesByAppUuid(@Param("applicationUuid") String applicationUuid);
 
-  void deleteApplicationBranchProjectBranchesByProjectBranchUuid(@Param("projectBranchUuid") String projectBranchUuid);
+  void deleteAppBranchProjectBranchesByProjectUuid(@Param("projectUuid") String projectUuid);
+
+  void deleteAppBranchProjectsByAppBranchUuid(@Param("branchUuid") String applicationBranchUuid);
+
+  void deleteAppBranchProjectBranchesByProjectBranchUuid(@Param("projectBranchUuid") String projectBranchUuid);
 
   void deletePortfolioProjectsByBranchUuid(@Param("branchUuid") String branchUuid);
 
index d84ed709dd7ef35b4dfb0cac50b07e531a2894bd..28b145031fcc4ec481e6c680a862372a2a6c3b9e 100644 (file)
     </foreach>
   </delete>
 
-  <delete id="deleteApplicationProjectsByApplicationUuid" parameterType="map">
+  <delete id="deleteAppProjectsByAppUuid" parameterType="map">
     DELETE
     FROM app_projects
     WHERE
       application_uuid=#{applicationUuid,jdbcType=VARCHAR}
   </delete>
 
-  <delete id="deleteApplicationBranchProjectBranchesByApplicationUuid" parameterType="map">
+    <delete id="deleteAppProjectsByProjectUuid" parameterType="map">
+    DELETE
+    FROM app_projects
+    WHERE
+      project_uuid=#{projectUuid,jdbcType=VARCHAR}
+  </delete>
+
+  <delete id="deleteAppBranchProjectBranchesByAppUuid" parameterType="map">
     DELETE
     FROM app_branch_project_branch
     WHERE
       application_uuid=#{applicationUuid,jdbcType=VARCHAR}
   </delete>
 
-  <delete id="deleteApplicationBranchProjects" parameterType="String">
+    <delete id="deleteAppBranchProjectBranchesByProjectUuid" parameterType="map">
+    DELETE
+    FROM app_branch_project_branch
+    WHERE
+      project_uuid=#{projectUuid,jdbcType=VARCHAR}
+  </delete>
+
+  <delete id="deleteAppBranchProjectsByAppBranchUuid" parameterType="String">
     DELETE
     FROM app_branch_project_branch
     WHERE
       application_branch_uuid=#{branchUuid,jdbcType=VARCHAR}
   </delete>
 
-  <delete id="deleteApplicationBranchProjectBranchesByProjectBranchUuid" parameterType="String">
+  <delete id="deleteAppBranchProjectBranchesByProjectBranchUuid" parameterType="String">
     DELETE
     FROM app_branch_project_branch
     WHERE project_branch_uuid=#{projectBranchUuid,jdbcType=VARCHAR}
index 580df5cd4a3e87fab6c401601c68f3b004dfce1b..ac34726bd91c4ecdbddfc831f348c50436fc911e 100644 (file)
@@ -632,7 +632,6 @@ public class PurgeDaoTest {
     assertThat(uuidsIn("app_projects", "application_uuid")).containsOnly(app.uuid(), otherApp.uuid());
     assertThat(uuidsIn("app_branch_project_branch", "application_branch_uuid")).containsOnly(otherAppBranch.uuid());
     assertThat(componentUuidsIn("properties")).containsOnly(otherAppBranch.uuid());
-
   }
 
   @Test
@@ -1402,6 +1401,29 @@ public class PurgeDaoTest {
       .containsExactlyInAnyOrder(tuple(portfolio1.uuid(), otherProject.getUuid()));
   }
 
+  @Test
+  public void deleteProject_deletes_app_projects() {
+    ProjectDto app = db.components().insertPrivateApplicationDto();
+    BranchDto appBranch = db.components().insertProjectBranch(app);
+
+    ProjectDto project = db.components().insertPublicProjectDto();
+    BranchDto projectBranch = db.components().insertProjectBranch(project);
+
+    ProjectDto otherProject = db.components().insertPublicProjectDto();
+
+    db.components().addApplicationProject(app, project, otherProject);
+    db.components().addProjectBranchToApplicationBranch(appBranch, projectBranch);
+
+    assertThat(db.countRowsOfTable("app_branch_project_branch")).isOne();
+
+    underTest.deleteProject(dbSession, project.getUuid(), project.getQualifier(), project.getName(), project.getKey());
+
+    assertThat(dbClient.applicationProjectsDao().selectProjects(dbSession, app.getUuid()))
+      .extracting(ProjectDto::getUuid)
+      .containsExactlyInAnyOrder(otherProject.getUuid());
+    assertThat(db.countRowsOfTable("app_branch_project_branch")).isZero();
+  }
+
   @Test
   public void deleteNonRootComponents_has_no_effect_when_parameter_is_empty() {
     DbSession dbSession = mock(DbSession.class);