diff options
15 files changed, 290 insertions, 44 deletions
diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java b/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java index 16b37ae57c0..b1cc497f535 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java @@ -62,7 +62,6 @@ public final class SqTables { "issues", "issue_changes", "live_measures", - "manual_measures", "metrics", "new_code_periods", "notifications", diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java index 82e568a729b..566c0e49393 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java @@ -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); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java index a0c5f1bf72c..a3537c1d5b0 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java @@ -52,6 +52,4 @@ public interface MetricMapper { int countEnabled(@Param("isCustom") @Nullable Boolean isCustom); void update(MetricDto metric); - - List<MetricDto> selectAvailableCustomMetricsByComponentUuid(String projectUuid); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml index acd5b2ea81d..a45239d3346 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml @@ -56,17 +56,6 @@ 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 diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 5eba94209d7..d191de19b5a 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -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, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java index 658a245257a..6aff35852bc 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java @@ -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()); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java index effbfc73be9..aefa1a5d9ad 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java @@ -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 index 00000000000..fa8e898ffe8 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java @@ -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 index 00000000000..b1cdc08bcf5 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresComponentUuidIndex.java @@ -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 index 00000000000..3856a5adce8 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresTable.java @@ -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 index 00000000000..562ff4bbff5 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java @@ -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 index 00000000000..6bfac6b4075 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresComponentUuidIndexTest.java @@ -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 index 00000000000..996837e4ff5 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresTableTest.java @@ -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 index 00000000000..84300f2fd70 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresComponentUuidIndexTest/schema.sql @@ -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 index 00000000000..f67221861ed --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/DropManualMeasuresTableTest/schema.sql @@ -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"); |