"issues",
"issue_changes",
"live_measures",
- "manual_measures",
"metrics",
"new_code_periods",
"notifications",
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);
}
int countEnabled(@Param("isCustom") @Nullable Boolean isCustom);
void update(MetricDto metric);
-
- List<MetricDto> selectAvailableCustomMetricsByComponentUuid(String projectUuid);
}
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
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,
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());
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
// DbVersion implementations
DbVersion00.class,
DbVersion90.class,
+ DbVersion91.class,
// migration steps
MigrationStepRegistryImpl.class,
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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());
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+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
--- /dev/null
+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");