aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-11-15 15:42:14 -0600
committersonartech <sonartech@sonarsource.com>2021-11-18 20:03:33 +0000
commitcc17da15ebea7d7585325f94368b7401505fa74f (patch)
tree0f0b5d9c61c654d4a849a639342d1de1cec7456f
parent8297ae1c8e625f812c28871d08423d73c03baa6f (diff)
downloadsonarqube-cc17da15ebea7d7585325f94368b7401505fa74f.tar.gz
sonarqube-cc17da15ebea7d7585325f94368b7401505fa74f.zip
SONAR-15398 Project is not removed from application_projects table when deleted
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java16
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java1
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java12
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml22
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java24
5 files changed, 62 insertions, 13 deletions
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 @@
</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}
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
@@ -1403,6 +1402,29 @@ public class PurgeDaoTest {
}
@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);