diff options
author | Zipeng WU <zipeng.wu@sonarsource.com> | 2021-06-25 17:54:21 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-07-07 20:03:24 +0000 |
commit | 45233feda278bc1e388c19bd9c454943344f6847 (patch) | |
tree | 3c69e48374b34d981d49d1c72dc9c742b98205d5 /server/sonar-db-migration | |
parent | 7994ab1cd1740e5b25842bc99cd05209e9813520 (diff) | |
download | sonarqube-45233feda278bc1e388c19bd9c454943344f6847.tar.gz sonarqube-45233feda278bc1e388c19bd9c454943344f6847.zip |
SONAR-10762 Drop manual measures table
Diffstat (limited to 'server/sonar-db-migration')
9 files changed, 290 insertions, 0 deletions
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"); |