]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13221 change PK to uuid of PROJECT_MEASURES table
authorJacek <jacek.poreda@sonarsource.com>
Wed, 15 Apr 2020 14:35:23 +0000 (16:35 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 25 May 2020 20:05:19 +0000 (20:05 +0000)
24 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDaoTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddPrimaryKeyOnUuidColumnOfProjectMeasuresTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddUuidColumnToProjectMeasures.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropIdColumnOfProjectMeasuresTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/MakeProjectMeasuresUuidColumnNotNullable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/PopulateProjectMeasureUuid.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddPrimaryKeyOnUuidColumnOfProjectMeasureTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddUuidToProjectMeasuresTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropIdColumnOfProjectMeasuresTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/MakeProjectMeasuresUuidColumnNotNullableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/PopulateProjectMeasuresUuidTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddPrimaryKeyOnUuidColumnOfProjectMeasureTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddUuidToProjectMeasuresTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropIdColumnOfProjectMeasuresTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/MakeProjectMeasuresUuidColumnNotNullableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/PopulateProjectMeasuresUuidTest/schema.sql [new file with mode: 0644]

index 2420349129e381ff304a4b446fc318b7c5ee75ab..3204ba1fe6ce96ec752c99864f9d1bc81c378e66 100644 (file)
@@ -23,11 +23,18 @@ import com.google.common.collect.Lists;
 import java.util.Collection;
 import java.util.List;
 import java.util.Optional;
+import org.sonar.core.util.UuidFactory;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
 
 public class MeasureDao implements Dao {
 
+  private final UuidFactory uuidFactory;
+
+  public MeasureDao(UuidFactory uuidFactory) {
+    this.uuidFactory = uuidFactory;
+  }
+
   public Optional<MeasureDto> selectLastMeasure(DbSession dbSession, String componentUuid, String metricKey) {
     return Optional.ofNullable(mapper(dbSession).selectLastMeasure(componentUuid, metricKey));
   }
@@ -50,11 +57,13 @@ public class MeasureDao implements Dao {
   }
 
   public void insert(DbSession session, MeasureDto measureDto) {
+    measureDto.setUuid(uuidFactory.create());
     mapper(session).insert(measureDto);
   }
 
   public void insert(DbSession session, Collection<MeasureDto> items) {
     for (MeasureDto item : items) {
+      item.setUuid(uuidFactory.create());
       insert(session, item);
     }
   }
index 6adbfc8e7e7a30d6c043042aa56d4dc6c026a3f2..cd3f006f86fb5eea60a17d8e758793715e2175a0 100644 (file)
@@ -27,6 +27,7 @@ import javax.annotation.Nullable;
 public class MeasureDto {
   private static final int MAX_TEXT_VALUE_LENGTH = 4000;
 
+  private String uuid;
   private Double value;
   private String textValue;
   private byte[] dataValue;
@@ -37,6 +38,14 @@ public class MeasureDto {
   private String analysisUuid;
   private int metricId;
 
+  public String getUuid() {
+    return uuid;
+  }
+
+  public void setUuid(String uuid) {
+    this.uuid = uuid;
+  }
+
   @CheckForNull
   public Double getValue() {
     return value;
index acdb80d718c18904bf589fb1731d2b0ed496e74b..6eb7c3a238dd0d71f30ce34cee170dd45b225a61 100644 (file)
@@ -4,6 +4,7 @@
 <mapper namespace="org.sonar.db.measure.MeasureMapper">
 
   <sql id="measureColumns">
+    pm.uuid as uuid,
     pm.metric_id as metricId,
     pm.component_uuid as componentUuid,
     pm.analysis_uuid as analysisUuid,
@@ -62,6 +63,7 @@
 
   <insert id="insert" parameterType="Measure" useGeneratedKeys="false">
     insert into project_measures (
+    uuid,
     value,
     metric_id,
     component_uuid,
@@ -72,6 +74,7 @@
     variation_value_1,
     measure_data)
     VALUES (
+    #{uuid, jdbcType=VARCHAR},
     #{value, jdbcType=DOUBLE},
     #{metricId, jdbcType=INTEGER},
     #{componentUuid, jdbcType=VARCHAR},
index ffca4c9f54ca7112c63a2ba8aab59bf86f1f8c96..5853db5ddb5c20a18c3224ed2804578180df5f7a 100644 (file)
@@ -673,7 +673,6 @@ CREATE UNIQUE INDEX "KEY_TYPE_KEE" ON "PROJECT_MAPPINGS"("KEY_TYPE", "KEE");
 CREATE INDEX "PROJECT_UUID" ON "PROJECT_MAPPINGS"("PROJECT_UUID");
 
 CREATE TABLE "PROJECT_MEASURES"(
-    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
     "VALUE" DOUBLE,
     "METRIC_ID" INTEGER NOT NULL,
     "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
@@ -688,9 +687,10 @@ CREATE TABLE "PROJECT_MEASURES"(
     "VARIATION_VALUE_3" DOUBLE,
     "VARIATION_VALUE_4" DOUBLE,
     "VARIATION_VALUE_5" DOUBLE,
-    "MEASURE_DATA" BLOB
+    "MEASURE_DATA" BLOB,
+    "UUID" VARCHAR(40) NOT NULL
 );
-ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("ID");
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("UUID");
 CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_ID");
 CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");
 
index 834d0927f184b39e814acea4ce672b8b87dea1e5..a2f66a36cb9edf5903cc725aa1ea39f7558bd5a6 100644 (file)
@@ -191,11 +191,13 @@ public class MeasureDaoTest {
   private void verifyMeasure(String componentUuid, String metricKey, String analysisUuid, String value) {
     Optional<MeasureDto> measure = underTest.selectMeasure(db.getSession(), analysisUuid, componentUuid, metricKey);
     assertThat(measure.map(MeasureDto::getData)).contains(value);
+    assertThat(measure.map(MeasureDto::getUuid)).isNotEmpty();
   }
 
   private void verifyMeasure(String componentUuid, String metricKey, String value) {
     Optional<MeasureDto> measure = underTest.selectLastMeasure(db.getSession(), componentUuid, metricKey);
     assertThat(measure.map(MeasureDto::getData)).contains(value);
+    assertThat(measure.map(MeasureDto::getUuid)).isNotEmpty();
   }
 
   private void verifyNoMeasure(String componentUuid, String metricKey, String analysisUuid) {
index f17f34fc2196c4ee6b9bae571ce21674c37acfcc..dbf194d7ffd379c416181e25ea06fe68fb510baa 100644 (file)
@@ -52,6 +52,12 @@ import org.sonar.server.platform.db.migration.version.v83.notifications.DropIdCo
 import org.sonar.server.platform.db.migration.version.v83.notifications.DropPrimaryKeyOnIdColumnOfNotificationTable;
 import org.sonar.server.platform.db.migration.version.v83.notifications.MakeNotificationUuidAndCreatedAtColumnsNotNullable;
 import org.sonar.server.platform.db.migration.version.v83.notifications.PopulateNotificationUuidAndCreatedAt;
+import org.sonar.server.platform.db.migration.version.v83.projectmeasures.AddPrimaryKeyOnUuidColumnOfProjectMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v83.projectmeasures.AddUuidColumnToProjectMeasures;
+import org.sonar.server.platform.db.migration.version.v83.projectmeasures.DropIdColumnOfProjectMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v83.projectmeasures.DropPrimaryKeyOnIdColumnOfProjectMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v83.projectmeasures.MakeProjectMeasuresUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.projectmeasures.PopulateProjectMeasureUuid;
 import org.sonar.server.platform.db.migration.version.v83.snapshots.issues.AddPrimaryKeyOnUuidColumnOfSnapshotsTable;
 import org.sonar.server.platform.db.migration.version.v83.snapshots.issues.DropIdColumnOfSnapshotsTable;
 import org.sonar.server.platform.db.migration.version.v83.snapshots.issues.DropPrimaryKeyOnIdColumnOfSnapshotsTable;
@@ -122,6 +128,14 @@ public class DbVersion83 implements DbVersion {
       .add(3431, "Drop primary key on 'ID' column of 'ACTIVE_RULE_PARAMS' table", DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable.class)
       .add(3432, "Add primary key on 'UUID' column of 'ACTIVE_RULE_PARAMS' table", AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable.class)
       .add(3433, "Drop column 'ID' of 'ACTIVE_RULE_PARAMS' table", DropIdColumnOfActiveRuleParametersTable.class)
+
+      // Migration on PROJECT_MEASURES table
+      .add(3434, "Add 'uuid' columns for 'PROJECT_MEASURES'", AddUuidColumnToProjectMeasures.class)
+      .add(3435, "Populate 'uuid' column for 'PROJECT_MEASURES'", PopulateProjectMeasureUuid.class)
+      .add(3436, "Make 'uuid' column not nullable for 'PROJECT_MEASURES'", MakeProjectMeasuresUuidColumnNotNullable.class)
+      .add(3437, "Drop primary key on 'ID' column of 'PROJECT_MEASURES' table", DropPrimaryKeyOnIdColumnOfProjectMeasuresTable.class)
+      .add(3438, "Add primary key on 'UUID' column of 'PROJECT_MEASURES' table", AddPrimaryKeyOnUuidColumnOfProjectMeasuresTable.class)
+      .add(3439, "Drop column 'ID' of 'PROJECT_MEASURES' table", DropIdColumnOfProjectMeasuresTable.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddPrimaryKeyOnUuidColumnOfProjectMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddPrimaryKeyOnUuidColumnOfProjectMeasuresTable.java
new file mode 100644 (file)
index 0000000..a8438e3
--- /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.projectmeasures;
+
+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 AddPrimaryKeyOnUuidColumnOfProjectMeasuresTable extends DdlChange {
+
+  public AddPrimaryKeyOnUuidColumnOfProjectMeasuresTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddPrimaryKeyBuilder("project_measures", "uuid").build());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddUuidColumnToProjectMeasures.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddUuidColumnToProjectMeasures.java
new file mode 100644 (file)
index 0000000..789ba4d
--- /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.projectmeasures;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddUuidColumnToProjectMeasures extends DdlChange {
+  private static final String TABLE = "project_measures";
+
+  private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+    .setColumnName("uuid")
+    .setIsNullable(true)
+    .setDefaultValue(null)
+    .setLimit(VarcharColumnDef.UUID_SIZE)
+    .build();
+
+  public AddUuidColumnToProjectMeasures(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+      .addColumn(uuidColumnDefinition)
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropIdColumnOfProjectMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropIdColumnOfProjectMeasuresTable.java
new file mode 100644 (file)
index 0000000..527031c
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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.projectmeasures;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIdColumnOfProjectMeasuresTable extends DdlChange {
+
+  public DropIdColumnOfProjectMeasuresTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new DropColumnsBuilder(getDialect(), "project_measures", "id").build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTable.java
new file mode 100644 (file)
index 0000000..a64d193
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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.projectmeasures;
+
+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.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnIdColumnOfProjectMeasuresTable extends DdlChange {
+
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator;
+
+  public DropPrimaryKeyOnIdColumnOfProjectMeasuresTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+    super(db);
+    this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(dropPrimaryKeySqlGenerator.generate("project_measures", "project_measures", "id"));
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/MakeProjectMeasuresUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/MakeProjectMeasuresUuidColumnNotNullable.java
new file mode 100644 (file)
index 0000000..cc1b682
--- /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.projectmeasures;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeProjectMeasuresUuidColumnNotNullable extends DdlChange {
+  private static final String TABLE = "project_measures";
+
+  private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+    .setColumnName("uuid")
+    .setIsNullable(false)
+    .setDefaultValue(null)
+    .setLimit(VarcharColumnDef.UUID_SIZE)
+    .build();
+
+  public MakeProjectMeasuresUuidColumnNotNullable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+      .updateColumn(uuidColumnDefinition)
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/PopulateProjectMeasureUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/PopulateProjectMeasureUuid.java
new file mode 100644 (file)
index 0000000..25cdf95
--- /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.projectmeasures;
+
+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 PopulateProjectMeasureUuid extends DataChange {
+
+  private final UuidFactory uuidFactory;
+
+  public PopulateProjectMeasureUuid(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 project_measures where uuid is null");
+    massUpdate.update("update project_measures 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/projectmeasures/AddPrimaryKeyOnUuidColumnOfProjectMeasureTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddPrimaryKeyOnUuidColumnOfProjectMeasureTableTest.java
new file mode 100644 (file)
index 0000000..c2d1490
--- /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.projectmeasures;
+
+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 org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidColumnOfProjectMeasureTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfProjectMeasureTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new AddPrimaryKeyOnUuidColumnOfProjectMeasuresTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertPrimaryKey("project_measures", "pk_project_measures", "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/projectmeasures/AddUuidToProjectMeasuresTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddUuidToProjectMeasuresTest.java
new file mode 100644 (file)
index 0000000..58089c4
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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.projectmeasures;
+
+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.UuidFactory;
+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 AddUuidToProjectMeasuresTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddUuidToProjectMeasuresTest.class, "schema.sql");
+
+  private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+
+  private DdlChange underTest = new AddUuidColumnToProjectMeasures(db.database());
+
+  @Before
+  public void setup() {
+    insertProjectMeasure(1L);
+    insertProjectMeasure(2L);
+    insertProjectMeasure(3L);
+  }
+
+  @Test
+  public void add_uuid_column_to_project_measures() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("project_measures", "uuid", Types.VARCHAR, 40, true);
+
+    assertThat(db.countSql("select count(id) from project_measures"))
+      .isEqualTo(3);
+  }
+
+  private void insertProjectMeasure(Long id) {
+    db.executeInsert("project_measures",
+      "id", id,
+      "metric_id", id + 100,
+      "analysis_uuid", uuidFactory.create(),
+      "component_uuid", uuidFactory.create());
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropIdColumnOfProjectMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropIdColumnOfProjectMeasuresTableTest.java
new file mode 100644 (file)
index 0000000..eb2dd71
--- /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.projectmeasures;
+
+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 org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropIdColumnOfProjectMeasuresTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfProjectMeasuresTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new DropIdColumnOfProjectMeasuresTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDoesNotExist("project_measures", "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/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest.java
new file mode 100644 (file)
index 0000000..9beaac7
--- /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.projectmeasures;
+
+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 org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+import org.sonar.server.platform.db.migration.version.v83.util.GetConstraintHelper;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest {
+
+  private static final String TABLE_NAME = "project_measures";
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest.class, "schema.sql");
+
+  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new GetConstraintHelper(db.database()));
+
+  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfProjectMeasuresTable(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/projectmeasures/MakeProjectMeasuresUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/MakeProjectMeasuresUuidColumnNotNullableTest.java
new file mode 100644 (file)
index 0000000..36aa156
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.projectmeasures;
+
+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 MakeProjectMeasuresUuidColumnNotNullableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(MakeProjectMeasuresUuidColumnNotNullableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new MakeProjectMeasuresUuidColumnNotNullable(db.database());
+
+  @Test
+  public void uuid_column_is_not_null() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("project_measures", "uuid", VARCHAR, null, false);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/PopulateProjectMeasuresUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/projectmeasures/PopulateProjectMeasuresUuidTest.java
new file mode 100644 (file)
index 0000000..248da1c
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * 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.projectmeasures;
+
+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 PopulateProjectMeasuresUuidTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(PopulateProjectMeasuresUuidTest.class, "schema.sql");
+
+  private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+  private DataChange underTest = new PopulateProjectMeasureUuid(db.database(), uuidFactory);
+
+  @Test
+  public void populate_uuids() throws SQLException {
+    insertProjectMeasure(1L);
+    insertProjectMeasure(2L);
+    insertProjectMeasure(3L);
+
+    underTest.execute();
+
+    verifyUuidsAreNotNull();
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    insertProjectMeasure(1L);
+    insertProjectMeasure(2L);
+    insertProjectMeasure(3L);
+
+    underTest.execute();
+    // re-entrant
+    underTest.execute();
+
+    verifyUuidsAreNotNull();
+  }
+
+  private void verifyUuidsAreNotNull() {
+    assertThat(db.select("select uuid from project_measures")
+      .stream()
+      .map(row -> row.get("UUID"))
+      .filter(Objects::isNull)
+      .collect(Collectors.toList())).isEmpty();
+  }
+
+  private void insertProjectMeasure(Long id) {
+    db.executeInsert("project_measures",
+      "id", id,
+      "metric_id", id + 100,
+      "analysis_uuid", uuidFactory.create(),
+      "component_uuid", uuidFactory.create());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddPrimaryKeyOnUuidColumnOfProjectMeasureTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddPrimaryKeyOnUuidColumnOfProjectMeasureTableTest/schema.sql
new file mode 100644 (file)
index 0000000..81664d4
--- /dev/null
@@ -0,0 +1,21 @@
+CREATE TABLE "PROJECT_MEASURES"(
+    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "VALUE" DOUBLE,
+    "METRIC_ID" INTEGER NOT NULL,
+    "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "TEXT_VALUE" VARCHAR(4000),
+    "ALERT_STATUS" VARCHAR(5),
+    "ALERT_TEXT" VARCHAR(4000),
+    "DESCRIPTION" VARCHAR(4000),
+    "PERSON_ID" INTEGER,
+    "VARIATION_VALUE_1" DOUBLE,
+    "VARIATION_VALUE_2" DOUBLE,
+    "VARIATION_VALUE_3" DOUBLE,
+    "VARIATION_VALUE_4" DOUBLE,
+    "VARIATION_VALUE_5" DOUBLE,
+    "MEASURE_DATA" BLOB
+);
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_ID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddUuidToProjectMeasuresTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/AddUuidToProjectMeasuresTest/schema.sql
new file mode 100644 (file)
index 0000000..3ff9ce0
--- /dev/null
@@ -0,0 +1,21 @@
+CREATE TABLE "PROJECT_MEASURES"(
+    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
+    "VALUE" DOUBLE,
+    "METRIC_ID" INTEGER NOT NULL,
+    "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "TEXT_VALUE" VARCHAR(4000),
+    "ALERT_STATUS" VARCHAR(5),
+    "ALERT_TEXT" VARCHAR(4000),
+    "DESCRIPTION" VARCHAR(4000),
+    "PERSON_ID" INTEGER,
+    "VARIATION_VALUE_1" DOUBLE,
+    "VARIATION_VALUE_2" DOUBLE,
+    "VARIATION_VALUE_3" DOUBLE,
+    "VARIATION_VALUE_4" DOUBLE,
+    "VARIATION_VALUE_5" DOUBLE,
+    "MEASURE_DATA" BLOB
+);
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("ID");
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_ID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropIdColumnOfProjectMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropIdColumnOfProjectMeasuresTableTest/schema.sql
new file mode 100644 (file)
index 0000000..f66002c
--- /dev/null
@@ -0,0 +1,22 @@
+CREATE TABLE "PROJECT_MEASURES"(
+    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "VALUE" DOUBLE,
+    "METRIC_ID" INTEGER NOT NULL,
+    "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "TEXT_VALUE" VARCHAR(4000),
+    "ALERT_STATUS" VARCHAR(5),
+    "ALERT_TEXT" VARCHAR(4000),
+    "DESCRIPTION" VARCHAR(4000),
+    "PERSON_ID" INTEGER,
+    "VARIATION_VALUE_1" DOUBLE,
+    "VARIATION_VALUE_2" DOUBLE,
+    "VARIATION_VALUE_3" DOUBLE,
+    "VARIATION_VALUE_4" DOUBLE,
+    "VARIATION_VALUE_5" DOUBLE,
+    "MEASURE_DATA" BLOB
+);
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_ID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest/schema.sql
new file mode 100644 (file)
index 0000000..fd01be5
--- /dev/null
@@ -0,0 +1,22 @@
+CREATE TABLE "PROJECT_MEASURES"(
+    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "VALUE" DOUBLE,
+    "METRIC_ID" INTEGER NOT NULL,
+    "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "TEXT_VALUE" VARCHAR(4000),
+    "ALERT_STATUS" VARCHAR(5),
+    "ALERT_TEXT" VARCHAR(4000),
+    "DESCRIPTION" VARCHAR(4000),
+    "PERSON_ID" INTEGER,
+    "VARIATION_VALUE_1" DOUBLE,
+    "VARIATION_VALUE_2" DOUBLE,
+    "VARIATION_VALUE_3" DOUBLE,
+    "VARIATION_VALUE_4" DOUBLE,
+    "VARIATION_VALUE_5" DOUBLE,
+    "MEASURE_DATA" BLOB
+);
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("ID");
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_ID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/MakeProjectMeasuresUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/MakeProjectMeasuresUuidColumnNotNullableTest/schema.sql
new file mode 100644 (file)
index 0000000..ba02385
--- /dev/null
@@ -0,0 +1,22 @@
+CREATE TABLE "PROJECT_MEASURES"(
+    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40),
+    "VALUE" DOUBLE,
+    "METRIC_ID" INTEGER NOT NULL,
+    "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "TEXT_VALUE" VARCHAR(4000),
+    "ALERT_STATUS" VARCHAR(5),
+    "ALERT_TEXT" VARCHAR(4000),
+    "DESCRIPTION" VARCHAR(4000),
+    "PERSON_ID" INTEGER,
+    "VARIATION_VALUE_1" DOUBLE,
+    "VARIATION_VALUE_2" DOUBLE,
+    "VARIATION_VALUE_3" DOUBLE,
+    "VARIATION_VALUE_4" DOUBLE,
+    "VARIATION_VALUE_5" DOUBLE,
+    "MEASURE_DATA" BLOB
+);
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("ID");
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_ID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/PopulateProjectMeasuresUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/projectmeasures/PopulateProjectMeasuresUuidTest/schema.sql
new file mode 100644 (file)
index 0000000..ba02385
--- /dev/null
@@ -0,0 +1,22 @@
+CREATE TABLE "PROJECT_MEASURES"(
+    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40),
+    "VALUE" DOUBLE,
+    "METRIC_ID" INTEGER NOT NULL,
+    "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "TEXT_VALUE" VARCHAR(4000),
+    "ALERT_STATUS" VARCHAR(5),
+    "ALERT_TEXT" VARCHAR(4000),
+    "DESCRIPTION" VARCHAR(4000),
+    "PERSON_ID" INTEGER,
+    "VARIATION_VALUE_1" DOUBLE,
+    "VARIATION_VALUE_2" DOUBLE,
+    "VARIATION_VALUE_3" DOUBLE,
+    "VARIATION_VALUE_4" DOUBLE,
+    "VARIATION_VALUE_5" DOUBLE,
+    "MEASURE_DATA" BLOB
+);
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("ID");
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_ID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");