diff options
author | Zipeng WU <zipeng.wu@sonarsource.com> | 2024-04-30 16:14:07 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-05-03 20:02:50 +0000 |
commit | 835fe2efc3643adbb8cf9632b83c8927ce96e7e9 (patch) | |
tree | 86a9eba599c4f43d41dbbf69f82959ff8ed5899f /server/sonar-db-dao | |
parent | 4cadd793241b54e5246f32e03fbdc7f838cd2d59 (diff) | |
download | sonarqube-835fe2efc3643adbb8cf9632b83c8927ce96e7e9.tar.gz sonarqube-835fe2efc3643adbb8cf9632b83c8927ce96e7e9.zip |
SONAR-22170 Removing a quality gate should remove QG conditions
Diffstat (limited to 'server/sonar-db-dao')
4 files changed, 23 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java index 9d484660ef0..f085811598f 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java @@ -117,6 +117,19 @@ class QualityGateConditionDaoIT { } @Test + void testDeleteForQualityGate() { + QualityGateConditionDto condition1 = insertQGCondition("qualityGateUuid"); + QualityGateConditionDto condition2 = insertQGCondition("qualityGateUuid"); + + underTest.deleteForQualityGate("qualityGateUuid", dbSession); + dbSession.commit(); + + assertThat(underTest.selectForQualityGate(dbSession, "qualityGateUuid")).isEmpty(); + assertThat(underTest.selectByUuid(condition1.getUuid(), dbSession)).isNull(); + assertThat(underTest.selectByUuid(condition2.getUuid(), dbSession)).isNull(); + } + + @Test void testUpdate() { QualityGateConditionDto condition1 = insertQGCondition("2"); QualityGateConditionDto condition2 = insertQGCondition("3"); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java index 4fa4145eef6..33399d630d2 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java @@ -46,6 +46,10 @@ public class QualityGateConditionDao implements Dao { mapper(session).delete(qGate.getUuid()); } + public void deleteForQualityGate(String qGateUuid, DbSession session) { + mapper(session).deleteForQualityGate(qGateUuid); + } + public void update(QualityGateConditionDto qGate, DbSession session) { mapper(session).update(qGate.setUpdatedAt(new Date())); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java index 7990c77c05b..5fba86f0cf6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java @@ -35,5 +35,7 @@ public interface QualityGateConditionMapper { void delete(String uuid); + void deleteForQualityGate(String qGateUuid); + void deleteConditionsWithInvalidMetrics(); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml index 0efc2c5d5b5..1159f6ec40e 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml @@ -37,6 +37,10 @@ delete from quality_gate_conditions where uuid=#{uuid} </update> + <update id="deleteForQualityGate" parameterType="String"> + delete from quality_gate_conditions where qgate_uuid=#{qGateUuid} + </update> + <update id="update" parameterType="QualityGateCondition"> update quality_gate_conditions set metric_uuid=#{metricUuid}, |