]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10301 delete from CE_TASK_INPUT when deleting a project
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 9 Feb 2018 10:57:49 +0000 (11:57 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 13 Feb 2018 13:50:35 +0000 (14:50 +0100)
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.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 4f3fc10738b067dd544edfcc079698b7e77f098b..edbe6931d792dfc45a51d3fef253236851866f48 100644 (file)
@@ -255,6 +255,10 @@ class PurgeCommands {
     purgeMapper.deleteCeTaskCharacteristicsOfCeActivityByProjectUuid(rootUuid);
     session.commit();
     profiler.stop();
+    profiler.start("deleteCeActivity (ce_task_input)");
+    purgeMapper.deleteCeTaskInputOfCeActivityByProjectUuid(rootUuid);
+    session.commit();
+    profiler.stop();
     profiler.start("deleteCeActivity (ce_activity)");
     purgeMapper.deleteCeActivityByProjectUuid(rootUuid);
     session.commit();
@@ -270,6 +274,10 @@ class PurgeCommands {
     purgeMapper.deleteCeTaskCharacteristicsOfCeQueueByProjectUuid(rootUuid);
     session.commit();
     profiler.stop();
+    profiler.start("deleteCeQueue (ce_task_input)");
+    purgeMapper.deleteCeTaskInputOfCeQueueByProjectUuid(rootUuid);
+    session.commit();
+    profiler.stop();
     profiler.start("deleteCeQueue (ce_queue)");
     purgeMapper.deleteCeQueueByProjectUuid(rootUuid);
     session.commit();
index 684160434175e042ee757f7824df2d8685ba0fe7..2db61704c6dfcd89a85c39b4ef98137eb2bae743 100644 (file)
@@ -92,6 +92,8 @@ public interface PurgeMapper {
 
   void deleteCeTaskCharacteristicsOfCeActivityByProjectUuid(@Param("projectUuid") String projectUuid);
 
+  void deleteCeTaskInputOfCeActivityByProjectUuid(@Param("projectUuid") String projectUuid);
+
   void deleteCeScannerContextOfCeActivityByProjectUuid(@Param("projectUuid") String projectUuid);
 
   void deleteCeActivityByProjectUuid(@Param("projectUuid") String projectUuid);
@@ -100,6 +102,8 @@ public interface PurgeMapper {
 
   void deleteCeTaskCharacteristicsOfCeQueueByProjectUuid(@Param("projectUuid") String projectUuid);
 
+  void deleteCeTaskInputOfCeQueueByProjectUuid(@Param("projectUuid") String projectUuid);
+
   void deleteCeQueueByProjectUuid(@Param("projectUuid") String projectUuid);
 
   void deleteWebhookDeliveriesByProjectUuid(@Param("projectUuid") String projectUuid);
index eb599b6b61bee94b0405586c71e0afdccdad9ad8..4f652c7cdc8a316a6b21be49c960ade31ff66e9d 100644 (file)
       task_uuid in (select uuid from ce_activity where component_uuid=#{projectUuid,jdbcType=VARCHAR})
   </delete>
 
+  <delete id="deleteCeTaskInputOfCeActivityByProjectUuid">
+    delete from ce_task_input
+    where
+      task_uuid in (select uuid from ce_activity where component_uuid=#{projectUuid,jdbcType=VARCHAR})
+  </delete>
+
   <delete id="deleteCeActivityByProjectUuid">
       delete from ce_activity where component_uuid=#{projectUuid,jdbcType=VARCHAR}
   </delete>
       task_uuid in (select uuid from ce_queue where component_uuid=#{projectUuid,jdbcType=VARCHAR})
   </delete>
 
+  <delete id="deleteCeTaskInputOfCeQueueByProjectUuid">
+    delete from ce_task_input
+    where
+      task_uuid in (select uuid from ce_queue where component_uuid=#{projectUuid,jdbcType=VARCHAR})
+  </delete>
+
   <delete id="deleteCeQueueByProjectUuid">
     delete from ce_queue where component_uuid=#{projectUuid,jdbcType=VARCHAR}
   </delete>
index 02d5b5cc797f173134e63df12c614de2831f3ecb..93b97c137721d096e236efe49f728f70894b50d7 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.db.purge;
 
 import com.google.common.collect.ImmutableList;
+import java.io.ByteArrayInputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -225,6 +226,31 @@ public class PurgeDaoTest {
     assertThat(dbTester.countRowsOfTable("ce_activity")).isEqualTo(1);
   }
 
+  @Test
+  public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_activity_when_deleting_project() {
+    ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject);
+
+    // Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project
+    CeActivityDto toBeDeleted = insertCeActivity(projectToBeDeleted);
+    insertCeTaskInput(toBeDeleted.getUuid());
+    CeActivityDto toNotDelete = insertCeActivity(anotherLivingProject);
+    insertCeTaskInput(toNotDelete.getUuid());
+    insertCeTaskInput("non existing task");
+    dbSession.commit();
+
+    underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
+    dbSession.commit();
+
+    assertThat(dbTester.select("select uuid as \"UUID\" from ce_activity"))
+      .extracting(row -> (String) row.get("UUID"))
+      .containsOnly(toNotDelete.getUuid());
+    assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_task_input"))
+      .extracting(row -> (String) row.get("UUID"))
+      .containsOnly(toNotDelete.getUuid(), "non existing task");
+  }
+
   @Test
   public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_activity_when_deleting_project() {
     ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
@@ -294,6 +320,31 @@ public class PurgeDaoTest {
     assertThat(dbTester.countSql("select count(*) from ce_queue where component_uuid='" + projectToBeDeleted.uuid() + "'")).isEqualTo(0);
   }
 
+  @Test
+  public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_queue_when_deleting_project() {
+    ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject);
+
+    // Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project
+    CeQueueDto toBeDeleted = insertCeQueue(projectToBeDeleted);
+    insertCeTaskInput(toBeDeleted.getUuid());
+    CeQueueDto toNotDelete = insertCeQueue(anotherLivingProject);
+    insertCeTaskInput(toNotDelete.getUuid());
+    insertCeTaskInput("non existing task");
+    dbSession.commit();
+
+    underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
+    dbSession.commit();
+
+    assertThat(dbTester.select("select uuid as \"UUID\" from ce_queue"))
+      .extracting(row -> (String) row.get("UUID"))
+      .containsOnly(toNotDelete.getUuid());
+    assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_task_input"))
+      .extracting(row -> (String) row.get("UUID"))
+      .containsOnly(toNotDelete.getUuid(), "non existing task");
+  }
+
   @Test
   public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_queue_when_deleting_project() {
     ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
@@ -776,6 +827,11 @@ public class PurgeDaoTest {
     dbSession.commit();
   }
 
+  private void insertCeTaskInput(String uuid) {
+    dbClient.ceTaskInputDao().insert(dbSession, uuid, new ByteArrayInputStream("some content man!".getBytes()));
+    dbSession.commit();
+  }
+
   private static PurgeableAnalysisDto getById(List<PurgeableAnalysisDto> snapshots, String uuid) {
     return snapshots.stream()
       .filter(snapshot -> uuid.equals(snapshot.getAnalysisUuid()))