From: Duarte Meneses Date: Mon, 15 Nov 2021 21:42:14 +0000 (-0600) Subject: SONAR-15398 Project is not removed from application_projects table when deleted X-Git-Tag: 9.2.0.49834~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cc17da15ebea7d7585325f94368b7401505fa74f;p=sonarqube.git SONAR-15398 Project is not removed from application_projects table when deleted --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java index c16a1741dd9..64139dbb480 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java @@ -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(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java index f86fa31d477..21211047e58 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java @@ -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); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java index f88c7e6dcda..eb9ba4d01d6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java @@ -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); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml index d84ed709dd7..28b145031fc 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml @@ -322,28 +322,42 @@ - + DELETE FROM app_projects WHERE application_uuid=#{applicationUuid,jdbcType=VARCHAR} - + + DELETE + FROM app_projects + WHERE + project_uuid=#{projectUuid,jdbcType=VARCHAR} + + + DELETE FROM app_branch_project_branch WHERE application_uuid=#{applicationUuid,jdbcType=VARCHAR} - + + DELETE + FROM app_branch_project_branch + WHERE + project_uuid=#{projectUuid,jdbcType=VARCHAR} + + + DELETE FROM app_branch_project_branch WHERE application_branch_uuid=#{branchUuid,jdbcType=VARCHAR} - + DELETE FROM app_branch_project_branch WHERE project_branch_uuid=#{projectBranchUuid,jdbcType=VARCHAR} diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java index 580df5cd4a3..ac34726bd91 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java @@ -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);