]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13221 Quality gate conditions
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 20 Apr 2020 21:15:35 +0000 (16:15 -0500)
committersonartech <sonartech@sonarsource.com>
Mon, 25 May 2020 20:05:19 +0000 (20:05 +0000)
39 files changed:
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddUuidColumnToQualityGateConditionsTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropIdColumnOfQualityGateConditionsTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/MakeQualityGateConditionsUuidColumnNotNullable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/PopulateQualityGateConditionsUuid.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddUuidColumnToQualityGateConditionsTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropIdColumnOfQualityGateConditionsTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/MakeQualityGateConditionsUuidColumnNotNullableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/PopulateQualityGateConditionsUuidTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddUuidColumnToQualityGateConditionsTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropIdColumnOfQualityGateConditionsTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/MakeQualityGateConditionsUuidColumnNotNullableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/PopulateQualityGateConditionsUuidTest/schema.sql [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CreateConditionAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeleteConditionAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/UpdateConditionAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/QualityGateConditionsUpdaterTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeleteConditionActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java

index aed1a4d5d145f3ab01411686b0b061e7bb770e61..29e1fff586cce163e3d791f212d8aa0561c1d0e9 100644 (file)
@@ -49,9 +49,10 @@ public class QualityGateServiceImplTest {
   private static final long METRIC_ID_2 = 753;
   private static final Metric METRIC_1 = mock(Metric.class);
   private static final Metric METRIC_2 = mock(Metric.class);
-  private static final QualityGateConditionDto CONDITION_1 = new QualityGateConditionDto().setId(321).setMetricId(METRIC_ID_1).setOperator("LT")
+  private static final QualityGateConditionDto CONDITION_1 = new QualityGateConditionDto().setUuid("321").setMetricId(METRIC_ID_1).setOperator("LT")
+    .setErrorThreshold("error_th");
+  private static final QualityGateConditionDto CONDITION_2 = new QualityGateConditionDto().setUuid("456").setMetricId(METRIC_ID_2).setOperator("GT")
     .setErrorThreshold("error_th");
-  private static final QualityGateConditionDto CONDITION_2 = new QualityGateConditionDto().setId(456).setMetricId(METRIC_ID_2).setOperator("GT").setErrorThreshold("error_th");
 
   private QualityGateDao qualityGateDao = mock(QualityGateDao.class);
   private QualityGateConditionDao qualityGateConditionDao = mock(QualityGateConditionDao.class);
index 8211eb64e3203915fc361af424bfdb177a1e91d8..88163b8eded9c6d89200ddfe6d9b6897a151c020 100644 (file)
@@ -34,12 +34,12 @@ public class QualityGateConditionDao implements Dao {
     return mapper(session).selectForQualityGate(qGateId);
   }
 
-  public QualityGateConditionDto selectById(long id, DbSession session) {
-    return mapper(session).selectById(id);
+  public QualityGateConditionDto selectByUuid(String uuid, DbSession session) {
+    return mapper(session).selectByUuid(uuid);
   }
 
   public void delete(QualityGateConditionDto qGate, DbSession session) {
-    mapper(session).delete(qGate.getId());
+    mapper(session).delete(qGate.getUuid());
   }
 
   public void update(QualityGateConditionDto qGate, DbSession session) {
index 9eee979c8e312196768192b02e93497265e83828..b21fcc53532ab26a60c01d6bd40b54e829047dd3 100644 (file)
@@ -31,7 +31,7 @@ public class QualityGateConditionDto {
   public static final String OPERATOR_GREATER_THAN = "GT";
   public static final String OPERATOR_LESS_THAN = "LT";
 
-  private long id;
+  private String uuid;
 
   private long qualityGateId;
 
@@ -47,12 +47,12 @@ public class QualityGateConditionDto {
 
   private Date updatedAt;
 
-  public long getId() {
-    return id;
+  public String getUuid() {
+    return uuid;
   }
 
-  public QualityGateConditionDto setId(long id) {
-    this.id = id;
+  public QualityGateConditionDto setUuid(String uuid) {
+    this.uuid = uuid;
     return this;
   }
 
index 2066c9dee4f3b15f906a71c5096100a62cc5df28..0261c1a34fb84903523992965f43437716efa6d1 100644 (file)
@@ -29,9 +29,9 @@ public interface QualityGateConditionMapper {
 
   void update(QualityGateConditionDto newCondition);
 
-  QualityGateConditionDto selectById(long id);
+  QualityGateConditionDto selectByUuid(String uuid);
 
-  void delete(long id);
+  void delete(String uuid);
 
   void deleteConditionsWithInvalidMetrics();
 }
index 3ab285eeaf6784025d1177795360ecf61d5bbf1a..c7b3c7099e3c9206da7ce075d012cafed2aebf98 100644 (file)
@@ -3,13 +3,13 @@
 
 <mapper namespace="org.sonar.db.qualitygate.QualityGateConditionMapper">
 
-  <insert id="insert" parameterType="QualityGateCondition" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    insert into quality_gate_conditions (qgate_id, metric_id, operator, value_error, created_at, updated_at)
-    values (#{qualityGateId}, #{metricId}, #{operator}, #{errorThreshold}, #{createdAt}, #{updatedAt})
+  <insert id="insert" parameterType="QualityGateCondition">
+    insert into quality_gate_conditions (uuid, qgate_id, metric_id, operator, value_error, created_at, updated_at)
+    values (#{uuid}, #{qualityGateId}, #{metricId}, #{operator}, #{errorThreshold}, #{createdAt}, #{updatedAt})
   </insert>
 
   <sql id="conditionColumns">
-    id, qgate_id as qualityGateId, metric_id as metricId, operator, value_error as errorThreshold,
+    uuid, qgate_id as qualityGateId, metric_id as metricId, operator, value_error as errorThreshold,
     created_at as createdAt, updated_at as updatedAt
   </sql>
 
     order by created_at asc
   </select>
 
-  <select id="selectById" parameterType="long" resultType="QualityGateCondition">
+  <select id="selectByUuid" parameterType="String" resultType="QualityGateCondition">
     select
     <include refid="conditionColumns"/>
-    from quality_gate_conditions where id=#{id}
+    from quality_gate_conditions where uuid=#{uuid}
   </select>
 
-  <update id="delete" parameterType="long">
-    delete from quality_gate_conditions where id=#{id}
+  <update id="delete" parameterType="String">
+    delete from quality_gate_conditions where uuid=#{uuid}
   </update>
 
   <update id="update" parameterType="QualityGateCondition">
@@ -36,7 +36,7 @@
     operator=#{operator},
     value_error=#{errorThreshold},
     updated_at=#{updatedAt}
-    where id=#{id}
+    where uuid=#{uuid}
   </update>
 
   <delete id="deleteConditionsWithInvalidMetrics">
index 6f05c6e3b41761d4294f0d8396934e9fa2c0f358..658a7077aa602ca7dac2462dfb8e9f06082493dd 100644 (file)
@@ -26,6 +26,7 @@ import java.util.stream.IntStream;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
+import org.sonar.core.util.Uuids;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.metric.MetricDto;
@@ -45,8 +46,8 @@ public class QualityGateConditionDaoTest {
   public void testInsert() {
     QualityGateConditionDto newCondition = insertQGCondition(1L, 2L, "GT", "20");
 
-    assertThat(newCondition.getId()).isNotNull();
-    QualityGateConditionDto actual = underTest.selectById(newCondition.getId(), dbSession);
+    assertThat(newCondition.getUuid()).isNotNull();
+    QualityGateConditionDto actual = underTest.selectByUuid(newCondition.getUuid(), dbSession);
     assertEquals(actual, newCondition);
   }
 
@@ -63,29 +64,29 @@ public class QualityGateConditionDaoTest {
     Collection<QualityGateConditionDto> conditions = underTest.selectForQualityGate(dbSession, qg1Id);
     assertThat(conditions).hasSize(qg1Conditions);
     assertThat(conditions)
-      .extracting("id")
+      .extracting("uuid")
       .containsExactly(conditions.stream()
         .sorted(Comparator.comparing(QualityGateConditionDto::getCreatedAt))
-        .map(QualityGateConditionDto::getId).toArray());
+        .map(QualityGateConditionDto::getUuid).toArray());
 
     conditions = underTest.selectForQualityGate(dbSession, qg2Id);
     assertThat(conditions).hasSize(qg2Conditions);
     assertThat(conditions)
-      .extracting("id")
+      .extracting("uuid")
       .containsExactly(conditions.stream()
         .sorted(Comparator.comparing(QualityGateConditionDto::getCreatedAt))
-        .map(QualityGateConditionDto::getId)
+        .map(QualityGateConditionDto::getUuid)
         .toArray());
 
     assertThat(underTest.selectForQualityGate(dbSession, 5)).isEmpty();
   }
 
   @Test
-  public void testSelectById() {
+  public void testSelectByUuid() {
     QualityGateConditionDto condition = insertQGCondition(1L, 2L, "GT", "20");
 
-    assertEquals(underTest.selectById(condition.getId(), dbSession), condition);
-    assertThat(underTest.selectById(42L, dbSession)).isNull();
+    assertEquals(underTest.selectByUuid(condition.getUuid(), dbSession), condition);
+    assertThat(underTest.selectByUuid("uuid1", dbSession)).isNull();
   }
 
   @Test
@@ -96,8 +97,8 @@ public class QualityGateConditionDaoTest {
     underTest.delete(condition1, dbSession);
     dbSession.commit();
 
-    assertThat(underTest.selectById(condition1.getId(), dbSession)).isNull();
-    assertThat(underTest.selectById(condition2.getId(), dbSession)).isNotNull();
+    assertThat(underTest.selectByUuid(condition1.getUuid(), dbSession)).isNull();
+    assertThat(underTest.selectByUuid(condition2.getUuid(), dbSession)).isNotNull();
   }
 
   @Test
@@ -106,7 +107,7 @@ public class QualityGateConditionDaoTest {
     QualityGateConditionDto condition2 = insertQGCondition(3L);
 
     QualityGateConditionDto newCondition1 = new QualityGateConditionDto()
-      .setId(condition1.getId())
+      .setUuid(condition1.getUuid())
       .setQualityGateId(condition1.getQualityGateId())
       .setMetricId(7L)
       .setOperator(">")
@@ -115,8 +116,8 @@ public class QualityGateConditionDaoTest {
     dbSession.commit();
 
 
-    assertEquals(underTest.selectById(condition1.getId(), dbSession), newCondition1);
-    assertEquals(underTest.selectById(condition2.getId(), dbSession), condition2);
+    assertEquals(underTest.selectByUuid(condition1.getUuid(), dbSession), newCondition1);
+    assertEquals(underTest.selectByUuid(condition2.getUuid(), dbSession), condition2);
   }
 
   @Test
@@ -131,9 +132,9 @@ public class QualityGateConditionDaoTest {
     dbTester.commit();
 
 
-    assertThat(underTest.selectById(condition1.getId(), dbSession)).isNotNull();
-    assertThat(underTest.selectById(condition2.getId(), dbSession)).isNull();
-    assertThat(underTest.selectById(condition3.getId(), dbSession)).isNull();
+    assertThat(underTest.selectByUuid(condition1.getUuid(), dbSession)).isNotNull();
+    assertThat(underTest.selectByUuid(condition2.getUuid(), dbSession)).isNull();
+    assertThat(underTest.selectByUuid(condition3.getUuid(), dbSession)).isNull();
   }
 
   private QualityGateConditionDto insertQGCondition(long qualityGateId) {
@@ -146,6 +147,7 @@ public class QualityGateConditionDaoTest {
 
   private QualityGateConditionDto insertQGCondition(long qualityGateId, long metricId, String operator, String threshold) {
     QualityGateConditionDto res = new QualityGateConditionDto()
+      .setUuid(Uuids.create())
       .setQualityGateId(qualityGateId)
       .setMetricId(metricId)
       .setOperator(operator)
index 596b2e044715584136d61ca27aa2f7fc6d61aece..1f49d797efb56e74a79b341674636e7d8cc38bbc 100644 (file)
@@ -94,6 +94,7 @@ public class QualityGateDbTester {
   @SafeVarargs
   public final QualityGateConditionDto addCondition(QualityGateDto qualityGate, MetricDto metric, Consumer<QualityGateConditionDto>... dtoPopulators) {
     QualityGateConditionDto condition = new QualityGateConditionDto().setQualityGateId(qualityGate.getId())
+      .setUuid(Uuids.createFast())
       .setMetricId(metric.getId())
       .setOperator("GT")
       .setErrorThreshold(randomNumeric(10));
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable.java
new file mode 100644 (file)
index 0000000..c69ffbe
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder;
+
+public class AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable extends DdlChange {
+
+  public AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddPrimaryKeyBuilder("quality_gate_conditions", "uuid").build());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddUuidColumnToQualityGateConditionsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddUuidColumnToQualityGateConditionsTable.java
new file mode 100644 (file)
index 0000000..34c7ed0
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.qualitygateconditions;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable;
+
+public class AddUuidColumnToQualityGateConditionsTable extends AddUuidColumnToTable {
+  private static final String TABLE = "quality_gate_conditions";
+
+  public AddUuidColumnToQualityGateConditionsTable(Database db) {
+    super(db, TABLE);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropIdColumnOfQualityGateConditionsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropIdColumnOfQualityGateConditionsTable.java
new file mode 100644 (file)
index 0000000..5ea1809
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.qualitygateconditions;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.DropIdColumn;
+
+public class DropIdColumnOfQualityGateConditionsTable extends DropIdColumn {
+  private static final String TABLE = "quality_gate_conditions";
+
+  public DropIdColumnOfQualityGateConditionsTable(Database db) {
+    super(db, TABLE);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable.java
new file mode 100644 (file)
index 0000000..c1b8987
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.qualitygateconditions;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.DropPrimaryKeyOnIdColumn;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable extends DropPrimaryKeyOnIdColumn {
+  private static final String TABLE_NAME = "quality_gate_conditions";
+
+  public DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+    super(db, dropPrimaryKeySqlGenerator, TABLE_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/MakeQualityGateConditionsUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/MakeQualityGateConditionsUuidColumnNotNullable.java
new file mode 100644 (file)
index 0000000..c1835b4
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.qualitygateconditions;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.MakeUuidColumnNotNullable;
+
+public class MakeQualityGateConditionsUuidColumnNotNullable extends MakeUuidColumnNotNullable {
+  private static final String TABLE = "quality_gate_conditions";
+
+  public MakeQualityGateConditionsUuidColumnNotNullable(Database db) {
+    super(db, TABLE);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/PopulateQualityGateConditionsUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/PopulateQualityGateConditionsUuid.java
new file mode 100644 (file)
index 0000000..8a7447d
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class PopulateQualityGateConditionsUuid extends DataChange {
+
+  private final UuidFactory uuidFactory;
+
+  public PopulateQualityGateConditionsUuid(Database db, UuidFactory uuidFactory) {
+    super(db);
+    this.uuidFactory = uuidFactory;
+  }
+
+  @Override
+  protected void execute(Context context) throws SQLException {
+    MassUpdate massUpdate = context.prepareMassUpdate();
+
+    massUpdate.select("select id from quality_gate_conditions where uuid is null order by id asc");
+    massUpdate.update("update quality_gate_conditions set uuid = ? where id = ?");
+
+    massUpdate.execute((row, update) -> {
+      update.setString(1, uuidFactory.create());
+      update.setLong(2, row.getLong(1));
+      return true;
+    });
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTableTest.java
new file mode 100644 (file)
index 0000000..3a19b4f
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTableTest.class, "schema.sql");
+
+  private DdlChange underTest = new AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertPrimaryKey("quality_gate_conditions", "pk_quality_gate_conditions", "uuid");
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddUuidColumnToQualityGateConditionsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddUuidColumnToQualityGateConditionsTableTest.java
new file mode 100644 (file)
index 0000000..a60293d
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddUuidColumnToQualityGateConditionsTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToQualityGateConditionsTableTest.class, "schema.sql");
+
+  private DdlChange underTest = new AddUuidColumnToQualityGateConditionsTable(db.database());
+
+  private UuidFactoryFast uuidFactory = UuidFactoryFast.getInstance();
+
+  @Before
+  public void setup() {
+    insertQualityGateCondition(1L);
+    insertQualityGateCondition(2L);
+    insertQualityGateCondition(3L);
+  }
+
+  @Test
+  public void add_uuid_column() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("quality_gate_conditions", "uuid", Types.VARCHAR, 40, true);
+
+    assertThat(db.countRowsOfTable("quality_gate_conditions"))
+      .isEqualTo(3);
+  }
+
+  private void insertQualityGateCondition(Long id) {
+    db.executeInsert("quality_gate_conditions",
+      "id", id,
+      "qgate_id", id + 1,
+      "period", id + 2);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropIdColumnOfQualityGateConditionsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropIdColumnOfQualityGateConditionsTableTest.java
new file mode 100644 (file)
index 0000000..a80e871
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropIdColumnOfQualityGateConditionsTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfQualityGateConditionsTableTest.class, "schema.sql");
+
+  private DdlChange underTest = new DropIdColumnOfQualityGateConditionsTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDoesNotExist("quality_gate_conditions", "id");
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest.java
new file mode 100644 (file)
index 0000000..20d7cdd
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.platform.db.migration.version.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+import org.sonar.server.platform.db.migration.version.v83.util.SqlHelper;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest {
+
+  private static final String TABLE_NAME = "quality_gate_conditions";
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest.class, "schema.sql");
+
+  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+
+  private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable(db.database(), dropPrimaryKeySqlGenerator);
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertNoPrimaryKey(TABLE_NAME);
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/MakeQualityGateConditionsUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/MakeQualityGateConditionsUuidColumnNotNullableTest.java
new file mode 100644 (file)
index 0000000..d045803
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeQualityGateConditionsUuidColumnNotNullableTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(MakeQualityGateConditionsUuidColumnNotNullableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new MakeQualityGateConditionsUuidColumnNotNullable(db.database());
+
+  @Test
+  public void uuid_column_is_not_nullable() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("quality_gate_conditions", "uuid", VARCHAR, null, false);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/PopulateQualityGateConditionsUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/PopulateQualityGateConditionsUuidTest.java
new file mode 100644 (file)
index 0000000..cb852dd
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PopulateQualityGateConditionsUuidTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(PopulateQualityGateConditionsUuidTest.class, "schema.sql");
+
+  private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+  private DataChange underTest = new PopulateQualityGateConditionsUuid(db.database(), uuidFactory);
+
+  @Test
+  public void populate_uuids() throws SQLException {
+    insertQualityGateCondition(1L);
+    insertQualityGateCondition(2L);
+    insertQualityGateCondition(3L);
+
+    underTest.execute();
+
+    verifyUuidsAreNotNull();
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    insertQualityGateCondition(1L);
+    insertQualityGateCondition(2L);
+    insertQualityGateCondition(3L);
+
+    underTest.execute();
+    // re-entrant
+    underTest.execute();
+
+    verifyUuidsAreNotNull();
+  }
+
+  private void verifyUuidsAreNotNull() {
+    assertThat(db.select("select uuid from quality_gate_conditions")
+      .stream()
+      .map(row -> row.get("UUID"))
+      .filter(Objects::isNull)
+      .collect(Collectors.toList())).isEmpty();
+  }
+
+  private void insertQualityGateCondition(Long id) {
+    db.executeInsert("quality_gate_conditions",
+      "id", id,
+      "uuid", uuidFactory.create(),
+      "qgate_id", id + 1,
+      "period", id + 2);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTableTest/schema.sql
new file mode 100644 (file)
index 0000000..eb63669
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+    "ID" INTEGER NOT NULL,
+    "UUID" VARCHAR(40) NOT NULL,
+    "QGATE_ID" INTEGER,
+    "METRIC_ID" INTEGER,
+    "PERIOD" INTEGER,
+    "OPERATOR" VARCHAR(3),
+    "VALUE_ERROR" VARCHAR(64),
+    "VALUE_WARNING" VARCHAR(64),
+    "CREATED_AT" TIMESTAMP,
+    "UPDATED_AT" TIMESTAMP
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddUuidColumnToQualityGateConditionsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/AddUuidColumnToQualityGateConditionsTableTest/schema.sql
new file mode 100644 (file)
index 0000000..a347b02
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "QGATE_ID" INTEGER,
+    "METRIC_ID" INTEGER,
+    "PERIOD" INTEGER,
+    "OPERATOR" VARCHAR(3),
+    "VALUE_ERROR" VARCHAR(64),
+    "VALUE_WARNING" VARCHAR(64),
+    "CREATED_AT" TIMESTAMP,
+    "UPDATED_AT" TIMESTAMP
+);
+ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropIdColumnOfQualityGateConditionsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropIdColumnOfQualityGateConditionsTableTest/schema.sql
new file mode 100644 (file)
index 0000000..6809369
--- /dev/null
@@ -0,0 +1,13 @@
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "QGATE_ID" INTEGER,
+    "METRIC_ID" INTEGER,
+    "PERIOD" INTEGER,
+    "OPERATOR" VARCHAR(3),
+    "VALUE_ERROR" VARCHAR(64),
+    "VALUE_WARNING" VARCHAR(64),
+    "CREATED_AT" TIMESTAMP,
+    "UPDATED_AT" TIMESTAMP
+);
+ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest/schema.sql
new file mode 100644 (file)
index 0000000..751e993
--- /dev/null
@@ -0,0 +1,13 @@
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "QGATE_ID" INTEGER,
+    "METRIC_ID" INTEGER,
+    "PERIOD" INTEGER,
+    "OPERATOR" VARCHAR(3),
+    "VALUE_ERROR" VARCHAR(64),
+    "VALUE_WARNING" VARCHAR(64),
+    "CREATED_AT" TIMESTAMP,
+    "UPDATED_AT" TIMESTAMP
+);
+ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/MakeQualityGateConditionsUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/MakeQualityGateConditionsUuidColumnNotNullableTest/schema.sql
new file mode 100644 (file)
index 0000000..dd69772
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "QGATE_ID" INTEGER,
+    "METRIC_ID" INTEGER,
+    "PERIOD" INTEGER,
+    "OPERATOR" VARCHAR(3),
+    "VALUE_ERROR" VARCHAR(64),
+    "VALUE_WARNING" VARCHAR(64),
+    "CREATED_AT" TIMESTAMP,
+    "UPDATED_AT" TIMESTAMP
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/PopulateQualityGateConditionsUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygateconditions/PopulateQualityGateConditionsUuidTest/schema.sql
new file mode 100644 (file)
index 0000000..2f6bb7f
--- /dev/null
@@ -0,0 +1,13 @@
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40),
+    "QGATE_ID" INTEGER,
+    "METRIC_ID" INTEGER,
+    "PERIOD" INTEGER,
+    "OPERATOR" VARCHAR(3),
+    "VALUE_ERROR" VARCHAR(64),
+    "VALUE_WARNING" VARCHAR(64),
+    "CREATED_AT" TIMESTAMP,
+    "UPDATED_AT" TIMESTAMP
+);
+ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("ID");
index bad67910b85779662f649ba9979abbfca3990fe6..81995bfb175f25c7a0e956e573de73369cf3684a 100644 (file)
@@ -31,6 +31,7 @@ import java.util.Set;
 import java.util.stream.Collectors;
 import javax.annotation.Nullable;
 import org.sonar.api.measures.Metric.ValueType;
+import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.metric.MetricDto;
@@ -92,6 +93,7 @@ public class QualityGateConditionsUpdater {
     checkConditionDoesNotExistOnSameMetric(getConditions(dbSession, qualityGate.getId()), metric);
 
     QualityGateConditionDto newCondition = new QualityGateConditionDto().setQualityGateId(qualityGate.getId())
+      .setUuid(Uuids.create())
       .setMetricId(metric.getId()).setMetricKey(metric.getKey())
       .setOperator(operator)
       .setErrorThreshold(errorThreshold);
index 37285a29b022e1cacec9019a83303d7d2af44b88..29bb767aa7fc1ed4d465c767fdb37da35b4636ab 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.qualitygate;
 
 import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.organization.OrganizationDto;
@@ -56,6 +57,7 @@ public class QualityGateUpdater {
 
     for (QualityGateConditionDto sourceCondition : dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getId())) {
       dbClient.gateConditionDao().insert(new QualityGateConditionDto()
+          .setUuid(Uuids.create())
           .setQualityGateId(destinationGate.getId())
           .setMetricId(sourceCondition.getMetricId())
           .setOperator(sourceCondition.getOperator())
index 8bd2f6c2d503d645c30cab6ad8a81d6200dc8eb3..dad60af40b2ea398fb01b84fdff8e7d4615d8d4c 100644 (file)
@@ -153,26 +153,26 @@ public class RegisterQualityGates implements Startable {
   }
 
   private static class QualityGateCondition {
-    private Long id;
+    private String uuid;
     private String metricKey;
     private String operator;
     private String errorThreshold;
 
     public static QualityGateCondition from(QualityGateConditionDto qualityGateConditionDto, Map<Long, String> mapping) {
       return new QualityGateCondition()
-        .setId(qualityGateConditionDto.getId())
+        .setUuid(qualityGateConditionDto.getUuid())
         .setMetricKey(mapping.get(qualityGateConditionDto.getMetricId()))
         .setOperator(qualityGateConditionDto.getOperator())
         .setErrorThreshold(qualityGateConditionDto.getErrorThreshold());
     }
 
     @CheckForNull
-    public Long getId() {
-      return id;
+    public String getUuid() {
+      return uuid;
     }
 
-    public QualityGateCondition setId(Long id) {
-      this.id = id;
+    public QualityGateCondition setUuid(String uuid) {
+      this.uuid = uuid;
       return this;
     }
 
@@ -205,7 +205,7 @@ public class RegisterQualityGates implements Startable {
 
     public QualityGateConditionDto toQualityGateDto(long qualityGateId) {
       return new QualityGateConditionDto()
-        .setId(id)
+        .setUuid(uuid)
         .setMetricKey(metricKey)
         .setOperator(operator)
         .setErrorThreshold(errorThreshold)
index c271aab9d58aa2ab09fec91e78682c27357953e4..16674d7b1029b6a8ef962d90358e3d6533735a69 100644 (file)
@@ -88,7 +88,8 @@ public class CreateConditionAction implements QualityGatesWsAction {
       wsSupport.checkCanEdit(qualityGate);
       QualityGateConditionDto condition = qualityGateConditionsUpdater.createCondition(dbSession, qualityGate, metric, operator, error);
       CreateConditionResponse.Builder createConditionResponse = CreateConditionResponse.newBuilder()
-        .setId(condition.getId())
+        // TODO
+        //.setId(condition.getUuid())
         .setMetric(condition.getMetricKey())
         .setError(condition.getErrorThreshold())
         .setOp(condition.getOperator());
index d3f9d9c643b53d948f0a6bdca7780e2ce194fd8a..7060e275513614e92b17226db8bfa8e517660e74 100644 (file)
@@ -61,12 +61,13 @@ public class DeleteConditionAction implements QualityGatesWsAction {
 
   @Override
   public void handle(Request request, Response response) {
-    long conditionId = request.mandatoryParamAsLong(PARAM_ID);
+    // TODO
+    String conditionUuid = request.mandatoryParam(PARAM_ID);
     try (DbSession dbSession = dbClient.openSession(false)) {
       OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
-      QualityGateConditionDto condition = wsSupport.getCondition(dbSession, conditionId);
+      QualityGateConditionDto condition = wsSupport.getCondition(dbSession, conditionUuid);
       QGateWithOrgDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndId(dbSession, organization, condition.getQualityGateId());
-      checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", conditionId, condition.getQualityGateId());
+      checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", conditionUuid, condition.getQualityGateId());
       wsSupport.checkCanEdit(qualityGateDto);
 
       dbClient.gateConditionDao().delete(condition, dbSession);
index d1d867f56613e659b50d883526326f4c5000f548..492dac9039fda5583b472033e9b1ac865d2ca4c2 100644 (file)
@@ -67,8 +67,8 @@ public class QualityGatesWsSupport {
       "No quality gate has been found for id %s in organization %s", qualityGateId, organization.getName());
   }
 
-  QualityGateConditionDto getCondition(DbSession dbSession, long id) {
-    return checkFound(dbClient.gateConditionDao().selectById(id, dbSession), "No quality gate condition with id '%d'", id);
+  QualityGateConditionDto getCondition(DbSession dbSession, String uuid) {
+    return checkFound(dbClient.gateConditionDao().selectByUuid(uuid, dbSession), "No quality gate condition with uuid '%s'", uuid);
   }
 
   boolean isQualityGateAdmin(OrganizationDto organization) {
index 7a2ae0a30cdc4d0f6438c526d552c37c0deaf7a7..ae96b03eca8f44be762f435241ced80e43b69535 100644 (file)
@@ -140,7 +140,8 @@ public class ShowAction implements QualityGatesWsAction {
       MetricDto metric = metricsById.get(metricId);
       checkState(metric != null, "Could not find metric with id %s", metricId);
       ShowWsResponse.Condition.Builder builder = ShowWsResponse.Condition.newBuilder()
-        .setId(condition.getId())
+        // TODO
+        //.setId(condition.getUuid())
         .setMetric(metric.getKey())
         .setOp(condition.getOperator());
       ofNullable(condition.getErrorThreshold()).ifPresent(builder::setError);
index 0f5f4589b1b5665162db9eec5dcfa794d532d1bd..a6a34ba65c8e21e2957db01e53b8eea62e395d6a 100644 (file)
@@ -77,7 +77,7 @@ public class UpdateConditionAction implements QualityGatesWsAction {
 
   @Override
   public void handle(Request request, Response response) {
-    int id = request.mandatoryParamAsInt(PARAM_ID);
+    String id = request.mandatoryParam(PARAM_ID);
     String metric = request.mandatoryParam(PARAM_METRIC);
     String operator = request.mandatoryParam(PARAM_OPERATOR);
     String error = request.mandatoryParam(PARAM_ERROR);
@@ -90,7 +90,8 @@ public class UpdateConditionAction implements QualityGatesWsAction {
       wsSupport.checkCanEdit(qualityGateDto);
       QualityGateConditionDto updatedCondition = qualityGateConditionsUpdater.updateCondition(dbSession, condition, metric, operator, error);
       UpdateConditionResponse.Builder updateConditionResponse = UpdateConditionResponse.newBuilder()
-        .setId(updatedCondition.getId())
+        // TODO
+       // .setId(updatedCondition.getUuid())
         .setMetric(updatedCondition.getMetricKey())
         .setError(updatedCondition.getErrorThreshold())
         .setOp(updatedCondition.getOperator());
index 8d6e1eea1c4c9db0266cae433cbeca18862ed822..c7470ddaebf4b4684f287f93376cb03d12613de2 100644 (file)
@@ -392,7 +392,7 @@ public class QualityGateConditionsUpdaterTest {
   }
 
   private void verifyCondition(QualityGateConditionDto dto, QualityGateDto qualityGate, MetricDto metric, String operator, String error) {
-    QualityGateConditionDto reloaded = db.getDbClient().gateConditionDao().selectById(dto.getId(), db.getSession());
+    QualityGateConditionDto reloaded = db.getDbClient().gateConditionDao().selectByUuid(dto.getUuid(), db.getSession());
     assertThat(reloaded.getQualityGateId()).isEqualTo(qualityGate.getId());
     assertThat(reloaded.getMetricId()).isEqualTo(metric.getId().longValue());
     assertThat(reloaded.getOperator()).isEqualTo(operator);
index 98b37354d971dba8bd540e6fc27d8aa7e684de65..3b1f58fecef1eee5637772016116cd808a92557c 100644 (file)
@@ -214,6 +214,7 @@ public class RegisterQualityGatesTest {
   public void builtin_quality_gate_with_incorrect_metricId_should_not_throw_an_exception() {
     insertMetrics();
     QualityGateConditionDto conditionDto = new QualityGateConditionDto()
+      .setUuid(Uuids.createFast())
       .setMetricId(-1) // This Id does not exist
       .setOperator(OPERATOR_GREATER_THAN)
       .setErrorThreshold("1");
index cb5f0c1514b7d318da2d3a8b42702bd2fce5fd5c..31b4829efc0f2fe3fb1ec4459d6a01ca54626467 100644 (file)
@@ -205,7 +205,7 @@ public class CreateConditionActionTest {
       .executeProtobuf(CreateConditionResponse.class);
 
     QualityGateConditionDto condition = new ArrayList<>(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId())).get(0);
-    assertThat(response.getId()).isEqualTo(condition.getId());
+    assertThat(response.getId()).isEqualTo(condition.getUuid());
     assertThat(response.getMetric()).isEqualTo(metric.getKey());
     assertThat(response.getOp()).isEqualTo("LT");
     assertThat(response.getError()).isEqualTo("45");
index 31ea34856af0c0849a05956a6e947eb3ef70b3f2..bdfdf5c02e7c437a42c2e0c1ece29c2f189eca66 100644 (file)
@@ -39,7 +39,6 @@ import org.sonar.server.ws.TestResponse;
 import org.sonar.server.ws.WsActionTester;
 
 import static java.lang.String.format;
-import static java.lang.String.valueOf;
 import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.tuple;
@@ -84,7 +83,7 @@ public class DeleteConditionActionTest {
     QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
 
     ws.newRequest()
-      .setParam(PARAM_ID, valueOf(qualityGateCondition.getId()))
+      .setParam(PARAM_ID, qualityGateCondition.getUuid())
       .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
 
@@ -99,7 +98,7 @@ public class DeleteConditionActionTest {
     QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
 
     ws.newRequest()
-      .setParam(PARAM_ID, valueOf(qualityGateCondition.getId()))
+      .setParam(PARAM_ID, qualityGateCondition.getUuid())
       .execute();
 
     assertThat(searchConditionsOf(qualityGate)).isEmpty();
@@ -114,7 +113,7 @@ public class DeleteConditionActionTest {
     QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
 
     TestResponse result = ws.newRequest()
-      .setParam(PARAM_ID, valueOf(qualityGateCondition.getId()))
+      .setParam(PARAM_ID, qualityGateCondition.getUuid())
       .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
 
@@ -133,7 +132,7 @@ public class DeleteConditionActionTest {
     expectedException.expectMessage(format("Operation forbidden for built-in Quality Gate '%s'", qualityGate.getName()));
 
     ws.newRequest()
-      .setParam(PARAM_ID, valueOf(qualityGateCondition.getId()))
+      .setParam(PARAM_ID, qualityGateCondition.getUuid())
       .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
@@ -149,25 +148,25 @@ public class DeleteConditionActionTest {
     expectedException.expect(ForbiddenException.class);
 
     ws.newRequest()
-      .setParam(PARAM_ID, valueOf(qualityGateCondition.getId()))
+      .setParam(PARAM_ID, qualityGateCondition.getUuid())
       .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
-  public void fail_if_condition_id_is_not_found() {
+  public void fail_if_condition_uuid_is_not_found() {
     OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_PROFILES, organization);
     QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
     MetricDto metric = db.measures().insertMetric();
     QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
-    long unknownConditionId = qualityGateCondition.getId() + 42L;
+    String unknownConditionUuid = "unknown";
 
     expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage("No quality gate condition with id '" + unknownConditionId + "'");
+    expectedException.expectMessage("No quality gate condition with uuid '" + unknownConditionUuid + "'");
 
     ws.newRequest()
-      .setParam(PARAM_ID, valueOf(unknownConditionId))
+      .setParam(PARAM_ID, unknownConditionUuid)
       .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
@@ -176,15 +175,15 @@ public class DeleteConditionActionTest {
   public void fail_when_condition_match_unknown_quality_gate() {
     OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_PROFILES, organization);
-    QualityGateConditionDto condition = new QualityGateConditionDto().setQualityGateId(123L);
+    QualityGateConditionDto condition = new QualityGateConditionDto().setUuid("uuid").setQualityGateId(123L);
     db.getDbClient().gateConditionDao().insert(condition, db.getSession());
     db.commit();
 
     expectedException.expect(IllegalStateException.class);
-    expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getId(), 123L));
+    expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getUuid(), 123L));
 
     ws.newRequest()
-      .setParam(PARAM_ID, valueOf(condition.getId()))
+      .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
@@ -199,10 +198,10 @@ public class DeleteConditionActionTest {
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric);
 
     expectedException.expect(IllegalStateException.class);
-    expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getId(), qualityGate.getId()));
+    expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getUuid(), qualityGate.getId()));
 
     ws.newRequest()
-      .setParam(PARAM_ID, valueOf(condition.getId()))
+      .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
index f92fd2d43ae2dfd940b1a1719bae690a705c37f0..00cdc03166edbb3725049ff7131d3e4a14a64f36 100644 (file)
@@ -89,8 +89,8 @@ public class ShowActionTest {
     assertThat(response.getConditionsList())
       .extracting(Condition::getId, Condition::getMetric, Condition::getOp, Condition::getError)
       .containsExactlyInAnyOrder(
-        tuple(condition1.getId(), metric1.getKey(), "GT", condition1.getErrorThreshold()),
-        tuple(condition2.getId(), metric2.getKey(), "LT", condition2.getErrorThreshold()));
+        tuple(condition1.getUuid(), metric1.getKey(), "GT", condition1.getErrorThreshold()),
+        tuple(condition2.getUuid(), metric2.getKey(), "LT", condition2.getErrorThreshold()));
   }
 
   @Test
index f655723b2f4043f298ba53c9b7923ab5bc2a12af..5dfe619802ca25d579646a90d34e5c7f4d04686c 100644 (file)
@@ -88,7 +88,7 @@ public class UpdateConditionActionTest {
 
     ws.newRequest()
       .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .setParam(PARAM_ID, Long.toString(condition.getId()))
+      .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
       .setParam(PARAM_ERROR, "90")
@@ -105,7 +105,7 @@ public class UpdateConditionActionTest {
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric);
 
     ws.newRequest()
-      .setParam(PARAM_ID, Long.toString(condition.getId()))
+      .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
       .setParam(PARAM_ERROR, "10")
@@ -125,13 +125,13 @@ public class UpdateConditionActionTest {
 
     CreateConditionResponse response = ws.newRequest()
       .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .setParam(PARAM_ID, Long.toString(condition.getId()))
+      .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
       .setParam(PARAM_ERROR, "45")
       .executeProtobuf(CreateConditionResponse.class);
 
-    assertThat(response.getId()).isEqualTo(condition.getId());
+    assertThat(response.getId()).isEqualTo(condition.getUuid());
     assertThat(response.getMetric()).isEqualTo(metric.getKey());
     assertThat(response.getOp()).isEqualTo("LT");
     assertThat(response.getError()).isEqualTo("45");
@@ -150,7 +150,7 @@ public class UpdateConditionActionTest {
 
     ws.newRequest()
       .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .setParam(PARAM_ID, Long.toString(condition.getId()))
+      .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
       .setParam(PARAM_ERROR, "10")
@@ -166,7 +166,7 @@ public class UpdateConditionActionTest {
     db.qualityGates().addCondition(qualityGate, metric);
 
     expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage("No quality gate condition with id '123'");
+    expectedException.expectMessage("No quality gate condition with uuid '123'");
 
     ws.newRequest()
       .setParam(PARAM_ORGANIZATION, organization.getKey())
@@ -182,16 +182,16 @@ public class UpdateConditionActionTest {
     OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES, organization);
     MetricDto metric = insertMetric();
-    QualityGateConditionDto condition = new QualityGateConditionDto().setQualityGateId(123L);
+    QualityGateConditionDto condition = new QualityGateConditionDto().setUuid("uuid").setQualityGateId(123L);
     db.getDbClient().gateConditionDao().insert(condition, dbSession);
     db.commit();
 
     expectedException.expect(IllegalStateException.class);
-    expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getId(), 123L));
+    expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getUuid(), 123L));
 
     ws.newRequest()
       .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .setParam(PARAM_ID, Long.toString(condition.getId()))
+      .setParam(PARAM_ID,condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
       .setParam(PARAM_ERROR, "90")
@@ -212,7 +212,7 @@ public class UpdateConditionActionTest {
 
     ws.newRequest()
       .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .setParam(PARAM_ID, Long.toString(condition.getId()))
+      .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "ABC")
       .setParam(PARAM_ERROR, "90")
@@ -234,7 +234,7 @@ public class UpdateConditionActionTest {
 
     ws.newRequest()
       .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .setParam(PARAM_ID, Long.toString(condition.getId()))
+      .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, updateOperator)
       .setParam(PARAM_ERROR, "90")
@@ -254,7 +254,7 @@ public class UpdateConditionActionTest {
 
     ws.newRequest()
       .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .setParam(PARAM_ID, Long.toString(condition.getId()))
+      .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
       .setParam(PARAM_ERROR, "90")