diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-10-01 16:59:24 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-10-02 16:06:01 +0200 |
commit | 1494dac2272c73ca4d13c25e895716ec5c356897 (patch) | |
tree | e3d63bbe2629916dffd057dfaa8461757409f564 /sonar-db | |
parent | fc7b6dc2a4558c0825a83987f6672cd19a428002 (diff) | |
download | sonarqube-1494dac2272c73ca4d13c25e895716ec5c356897.tar.gz sonarqube-1494dac2272c73ca4d13c25e895716ec5c356897.zip |
Improve deletion of project to deal with subviews/tech projects
Diffstat (limited to 'sonar-db')
4 files changed, 64 insertions, 4 deletions
diff --git a/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml index 6307b26275b..8dcfbf87609 100644 --- a/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml @@ -83,7 +83,7 @@ </select> <select id="selectComponentsByProjectUuid" resultType="org.sonar.db.purge.IdUuidPair" parameterType="String"> - select id, uuid from projects where project_uuid=#{uuid} + select id, uuid from projects where project_uuid=#{uuid} or uuid=#{uuid} </select> <delete id="deleteSnapshotMeasures" parameterType="map"> diff --git a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java index 0ff1acd378f..ac64984651a 100644 --- a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java @@ -117,6 +117,36 @@ public class PurgeDaoTest { } @Test + public void delete_view_and_child() { + dbTester.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml"); + + underTest.deleteProject(dbSession, "A"); + dbSession.commit(); + assertThat(dbTester.countSql("select count(id) from projects where uuid='A'")).isZero(); + assertThat(dbTester.countRowsOfTable("projects")).isZero(); + } + + @Test + public void delete_view_sub_view_and_tech_project() { + dbTester.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml"); + + // technical project + underTest.deleteProject(dbSession, "D"); + dbSession.commit(); + assertThat(dbTester.countSql("select count(id) from projects where uuid='D'")).isZero(); + + // sub view + underTest.deleteProject(dbSession, "B"); + dbSession.commit(); + assertThat(dbTester.countSql("select count(id) from projects where uuid='B'")).isZero(); + + // view + underTest.deleteProject(dbSession, "A"); + dbSession.commit(); + assertThat(dbTester.countSql("select count(id) from projects where uuid='A'")).isZero(); + } + + @Test public void should_delete_old_closed_issues() { dbTester.prepareDbUnit(getClass(), "should_delete_old_closed_issues.xml"); underTest.purge(newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler()); diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml index fac178de73e..dc6abb440dc 100644 --- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml +++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml @@ -2,7 +2,7 @@ <!-- root --> <projects id="1" enabled="[true]" root_id="[null]" - uuid="A" project_uuid="A" module_uuid="[null]" module_uuid_path="." + uuid="A" project_uuid="A" module_uuid="[null]" module_uuid_path=".A." long_name="[null]" scope="PRJ" qualifier="TRK" kee="project" name="project" description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]"/> @@ -54,7 +54,7 @@ <!-- modules --> <projects id="2" enabled="[true]" root_id="1" - uuid="B" project_uuid="A" module_uuid="A" module_uuid_path=".A." + uuid="B" project_uuid="A" module_uuid="A" module_uuid_path=".A.B." long_name="[null]" scope="PRJ" qualifier="BRC" kee="module1" name="module1" description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]"/> @@ -72,7 +72,7 @@ <projects id="3" enabled="[false]" root_id="1" - uuid="C" project_uuid="A" module_uuid="A" module_uuid_path=".A." + uuid="C" project_uuid="A" module_uuid="A" module_uuid_path=".A.C." long_name="[null]" scope="PRJ" qualifier="BRC" kee="module2" name="module2" description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]"/> diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/view_sub_view_and_tech_project.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/view_sub_view_and_tech_project.xml new file mode 100644 index 00000000000..f2e519eb559 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/view_sub_view_and_tech_project.xml @@ -0,0 +1,30 @@ +<dataset> + + <!-- view --> + <projects id="1" enabled="[true]" root_id="[null]" + uuid="A" project_uuid="A" module_uuid="[null]" module_uuid_path=".A." + long_name="[null]" scope="PRJ" qualifier="VW" kee="view" name="view" + description="[null]" language="[null]" copy_resource_id="[null]" person_id="[null]" + authorization_updated_at="[null]"/> + + <!-- sub views --> + <projects id="2" enabled="[true]" root_id="1" + uuid="B" project_uuid="A" module_uuid="A" module_uuid_path=".A.B." + long_name="[null]" scope="PRJ" qualifier="SVW" kee="subview1" name="subview2" + description="[null]" language="[null]" copy_resource_id="[null]" person_id="[null]" + authorization_updated_at="[null]"/> + + <projects id="3" enabled="[false]" root_id="1" + uuid="C" project_uuid="A" module_uuid="A" module_uuid_path=".A.C." + long_name="[null]" scope="PRJ" qualifier="SVW" kee="subview2" name="subview2" + description="[null]" language="[null]" copy_resource_id="[null]" person_id="[null]" + authorization_updated_at="[null]"/> + + <!-- technical project of module 2--> + <projects id="4" enabled="[false]" root_id="3" + uuid="D" project_uuid="A" module_uuid="C" module_uuid_path=".A.C." + long_name="[null]" scope="FIL" qualifier="TRK" kee="TechProject" name="TechProject" + description="[null]" language="[null]" copy_resource_id="[null]" person_id="[null]" + authorization_updated_at="[null]"/> + +</dataset> |