]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10762 Drop manual measures table
authorZipeng WU <zipeng.wu@sonarsource.com>
Fri, 25 Jun 2021 15:54:21 +0000 (17:54 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 7 Jul 2021 20:03:24 +0000 (20:03 +0000)
15 files changed:
server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresComponentUuidIndex.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresTable.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresComponentUuidIndexTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresComponentUuidIndexTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresTableTest/schema.sql [new file with mode: 0644]

index 16b37ae57c0367d276f58e99fced8583f95dbb17..b1cc497f535f30ecd8eadba48d4740bcafca651b 100644 (file)
@@ -62,7 +62,6 @@ public final class SqTables {
     "issues",
     "issue_changes",
     "live_measures",
-    "manual_measures",
     "metrics",
     "new_code_periods",
     "notifications",
index 82e568a729b40aab2ed75854ea9cb246330f478d..566c0e4939341c67d8878383679ae502ad0da889 100644 (file)
@@ -102,10 +102,6 @@ public class MetricDao implements Dao {
     return newArrayList(Collections2.filter(mapper(session).selectDomains(), new NotEmptyPredicate()));
   }
 
-  public List<MetricDto> selectAvailableCustomMetricsByComponentUuid(DbSession session, String projectUuid) {
-    return mapper(session).selectAvailableCustomMetricsByComponentUuid(projectUuid);
-  }
-
   public List<MetricDto> selectByUuids(DbSession session, Set<String> uuidsSet) {
     return executeLargeInputs(new ArrayList<>(uuidsSet), mapper(session)::selectByUuids);
   }
index a0c5f1bf72c4018788818256633affc20a0d3d81..a3537c1d5b04d27184953164e7687982cf3686db 100644 (file)
@@ -52,6 +52,4 @@ public interface MetricMapper {
   int countEnabled(@Param("isCustom") @Nullable Boolean isCustom);
 
   void update(MetricDto metric);
-
-  List<MetricDto> selectAvailableCustomMetricsByComponentUuid(String projectUuid);
 }
index acd5b2ea81d52f2bfc0b5d3c0e2c0d0db8bcc7dc..a45239d334613ba2a17aa675f1b4080cb0d87e4f 100644 (file)
     ORDER BY UPPER(m.short_name), m.short_name
   </select>
 
-  <select id="selectAvailableCustomMetricsByComponentUuid" resultType="org.sonar.db.metric.MetricDto">
-    select
-    <include refid="metricColumns"/>
-    from metrics m
-    left join manual_measures mm on mm.metric_uuid = m.uuid and mm.component_uuid=#{componentUuid}
-    where m.enabled=${_true}
-    and m.user_managed=${_true}
-    and mm.uuid is null
-    ORDER BY UPPER(m.short_name), m.short_name
-  </select>
-
   <select id="countEnabled" resultType="Integer">
     SELECT COUNT(1)
     FROM metrics m
index 5eba94209d76705e0a6439ae8d109f2431a1f236..d191de19b5ad88edf5c71fe08e09866026facd6c 100644 (file)
@@ -442,20 +442,6 @@ ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID"
 CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
 CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_UUID");
 
-CREATE TABLE "MANUAL_MEASURES"(
-    "UUID" VARCHAR(40) NOT NULL,
-    "VALUE" DOUBLE,
-    "TEXT_VALUE" VARCHAR(4000),
-    "USER_UUID" VARCHAR(255),
-    "DESCRIPTION" VARCHAR(4000),
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
-    "METRIC_UUID" VARCHAR(40) NOT NULL
-);
-ALTER TABLE "MANUAL_MEASURES" ADD CONSTRAINT "PK_MANUAL_MEASURES" PRIMARY KEY("UUID");
-CREATE INDEX "MANUAL_MEASURES_COMPONENT_UUID" ON "MANUAL_MEASURES"("COMPONENT_UUID");
-
 CREATE TABLE "METRICS"(
     "UUID" VARCHAR(40) NOT NULL,
     "NAME" VARCHAR(64) NOT NULL,
index 658a245257a0677c2adaf1ac3a8e1002aaadad0b..6aff35852bc575f798705f474c736371813579c6 100644 (file)
@@ -308,18 +308,6 @@ public class MetricDaoTest {
     assertThat(result).hasSize(3);
   }
 
-  @Test
-  public void selectAvailableByComponentUuid() {
-    underTest.insert(dbSession, newMetricDto().setUserManaged(true).setEnabled(true).setKey("metric-key"));
-    underTest.insert(dbSession, newMetricDto().setUserManaged(false).setEnabled(true).setKey("another-metric-key"));
-    underTest.insert(dbSession, newMetricDto().setUserManaged(true).setEnabled(false).setKey("third-metric-key"));
-
-    List<MetricDto> result = underTest.selectAvailableCustomMetricsByComponentUuid(dbSession, "project-uuid");
-
-    assertThat(result).hasSize(1)
-      .extracting("key").containsOnly("metric-key");
-  }
-
   private void assertEquals(MetricDto expected, MetricDto result) {
     assertThat(result.getKey()).isEqualTo(expected.getKey());
     assertThat(result.getShortName()).isEqualTo(expected.getShortName());
index effbfc73be93a35f4ba8922e8cdcf8ad2d955062..aefa1a5d9ad6773b67d64c9c5f31f13bd9b18162 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.server.platform.db.migration.step.MigrationStepRegistryImpl;
 import org.sonar.server.platform.db.migration.step.MigrationStepsProvider;
 import org.sonar.server.platform.db.migration.version.v00.DbVersion00;
 import org.sonar.server.platform.db.migration.version.v90.DbVersion90;
+import org.sonar.server.platform.db.migration.version.v91.DbVersion91;
 
 public class MigrationConfigurationModule extends Module {
   @Override
@@ -36,6 +37,7 @@ public class MigrationConfigurationModule extends Module {
       // DbVersion implementations
       DbVersion00.class,
       DbVersion90.class,
+      DbVersion91.class,
 
       // migration steps
       MigrationStepRegistryImpl.class,
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java
new file mode 100644 (file)
index 0000000..fa8e898
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v91;
+
+import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
+import org.sonar.server.platform.db.migration.version.DbVersion;
+import org.sonar.server.platform.db.migration.version.v90.AddPrimaryKeyOnKeeColumnOfIssuesTable;
+import org.sonar.server.platform.db.migration.version.v90.AddPrimaryKeyOnUuidColumnOfCeActivityTable;
+import org.sonar.server.platform.db.migration.version.v90.AddPrimaryKeyOnUuidColumnOfEventsTable;
+import org.sonar.server.platform.db.migration.version.v90.AddPrimaryKeyOnUuidColumnOfSnapshotsTable;
+import org.sonar.server.platform.db.migration.version.v90.DropAnalysesUuidIndex;
+import org.sonar.server.platform.db.migration.version.v90.DropCeActivityUuidIndex;
+import org.sonar.server.platform.db.migration.version.v90.DropEventsUuidIndex;
+import org.sonar.server.platform.db.migration.version.v90.DropIssuesKeeIndex;
+import org.sonar.server.platform.db.migration.version.v90.DropPrimaryKeyOnKeeColumnOfIssuesTable;
+import org.sonar.server.platform.db.migration.version.v90.DropPrimaryKeyOnUuidColumnOfCeActivityTable;
+import org.sonar.server.platform.db.migration.version.v90.DropPrimaryKeyOnUuidColumnOfEventsTable;
+import org.sonar.server.platform.db.migration.version.v90.DropPrimaryKeyOnUuidColumnOfSnapshotsTable;
+
+public class DbVersion91 implements DbVersion {
+  @Override
+  public void addSteps(MigrationStepRegistry registry) {
+    registry
+      .add(6001, "Drop 'manual_measures_component_uuid' index", DropManualMeasuresComponentUuidIndex.class)
+      .add(6002, "Drop 'manual_measures' table", DropManualMeasuresTable.class);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresComponentUuidIndex.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresComponentUuidIndex.java
new file mode 100644 (file)
index 0000000..b1cdc08
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v91;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropIndexChange;
+
+public class DropManualMeasuresComponentUuidIndex extends DropIndexChange {
+  private static final String INDEX_NAME = "manual_measures_component_uuid";
+  private static final String TABLE_NAME = "manual_measures";
+
+  public DropManualMeasuresComponentUuidIndex(Database db) {
+    super(db, INDEX_NAME, TABLE_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresTable.java
new file mode 100644 (file)
index 0000000..3856a5a
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v91;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropManualMeasuresTable extends DdlChange {
+  private static final String TABLE_NAME = "manual_measures";
+
+  public DropManualMeasuresTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new DropTableBuilder(getDialect(), TABLE_NAME).build());
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java
new file mode 100644 (file)
index 0000000..562ff4b
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v91;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationCount;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
+
+public class DbVersion91Test {
+
+  private final DbVersion91 underTest = new DbVersion91();
+
+  @Test
+  public void verify_no_support_component() {
+    assertThat(underTest.getSupportComponents()).isEmpty();
+  }
+
+  @Test
+  public void migrationNumber_starts_at_6001() {
+    verifyMinimumMigrationNumber(underTest, 6001);
+  }
+
+  @Test
+  public void verify_migration_count() {
+    verifyMigrationCount(underTest, 2);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresComponentUuidIndexTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresComponentUuidIndexTest.java
new file mode 100644 (file)
index 0000000..6bfac6b
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v91;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class DropManualMeasuresComponentUuidIndexTest {
+  private static final String INDEX_NAME = "manual_measures_component_uuid";
+  private static final String TABLE_NAME = "manual_measures";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(DropManualMeasuresComponentUuidIndexTest.class, "schema.sql");
+
+  private final DropManualMeasuresComponentUuidIndex underTest = new DropManualMeasuresComponentUuidIndex(db.database());
+
+  @Test
+  public void migration_should_drop_unique_index_on_manual_measures() throws SQLException {
+    db.assertIndex(TABLE_NAME, INDEX_NAME, "component_uuid");
+    underTest.execute();
+    db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
+  }
+
+  @Test
+  public void migration_should_be_reentrant() throws SQLException {
+    db.assertIndex(TABLE_NAME, INDEX_NAME, "component_uuid");
+    underTest.execute();
+    // re-entrant
+    underTest.execute();
+    db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresTableTest.java
new file mode 100644 (file)
index 0000000..996837e
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v91;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class DropManualMeasuresTableTest {
+  private static final String TABLE_NAME = "manual_measures";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(DropManualMeasuresTableTest.class, "schema.sql");
+
+  private final DropManualMeasuresTable underTest = new DropManualMeasuresTable(db.database());
+
+  @Test
+  public void migration_should_drop_unique_index_on_manual_measures() throws SQLException {
+    db.assertTableExists(TABLE_NAME);
+    underTest.execute();
+    db.assertTableDoesNotExist(TABLE_NAME);
+  }
+
+  @Test
+  public void migration_should_be_reentrant() throws SQLException {
+    db.assertTableExists(TABLE_NAME);
+    underTest.execute();
+    // re-entrant
+    underTest.execute();
+    db.assertTableDoesNotExist(TABLE_NAME);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresComponentUuidIndexTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresComponentUuidIndexTest/schema.sql
new file mode 100644 (file)
index 0000000..84300f2
--- /dev/null
@@ -0,0 +1,13 @@
+CREATE TABLE "MANUAL_MEASURES"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "VALUE" DOUBLE,
+    "TEXT_VALUE" VARCHAR(4000),
+    "USER_UUID" VARCHAR(255),
+    "DESCRIPTION" VARCHAR(4000),
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "METRIC_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "MANUAL_MEASURES" ADD CONSTRAINT "PK_MANUAL_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MANUAL_MEASURES_COMPONENT_UUID" ON "MANUAL_MEASURES"("COMPONENT_UUID");
\ No newline at end of file
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresTableTest/schema.sql
new file mode 100644 (file)
index 0000000..f672218
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "MANUAL_MEASURES"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "VALUE" DOUBLE,
+    "TEXT_VALUE" VARCHAR(4000),
+    "USER_UUID" VARCHAR(255),
+    "DESCRIPTION" VARCHAR(4000),
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "METRIC_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "MANUAL_MEASURES" ADD CONSTRAINT "PK_MANUAL_MEASURES" PRIMARY KEY("UUID");