From 10e37ca6cfe52d7419852de698ac67993b0f01c4 Mon Sep 17 00:00:00 2001 From: Javier Garcia Orduna Date: Mon, 14 Oct 2024 14:36:35 +0200 Subject: [PATCH] SONAR-23312 Drop column issues.from_hotspot --- server/sonar-db-dao/src/schema/schema-sq.ddl | 1 - .../v108/DropColumnFromHotspotInIssuesIT.java | 51 +++++++++++++++++++ .../migration/version/v108/DbVersion108.java | 3 +- .../v108/DropColumnFromHotspotInIssues.java | 32 ++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropColumnFromHotspotInIssuesIT.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropColumnFromHotspotInIssues.java diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 9eea010c9f6..10aafb7e3af 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -479,7 +479,6 @@ CREATE TABLE "ISSUES"( "PROJECT_UUID" CHARACTER VARYING(50), "LOCATIONS" BINARY LARGE OBJECT, "ISSUE_TYPE" TINYINT, - "FROM_HOTSPOT" BOOLEAN, "QUICK_FIX_AVAILABLE" BOOLEAN, "RULE_DESCRIPTION_CONTEXT_KEY" CHARACTER VARYING(50), "MESSAGE_FORMATTINGS" BINARY LARGE OBJECT, diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropColumnFromHotspotInIssuesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropColumnFromHotspotInIssuesIT.java new file mode 100644 index 00000000000..9aef15ead25 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropColumnFromHotspotInIssuesIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +class DropColumnFromHotspotInIssuesIT { + private static final String TABLE_NAME = "issues"; + private static final String COLUMN_NAME = "from_hotspot"; + + @RegisterExtension + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropColumnFromHotspotInIssues.class); + private final DdlChange underTest = new DropColumnFromHotspotInIssues(db.database()); + + @Test + void drops_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.BOOLEAN, null, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.BOOLEAN, null, true); + underTest.execute(); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java index b908e920137..2d001f4d95e 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java @@ -48,7 +48,8 @@ public class DbVersion108 implements DbVersion { .add(10_8_005, "Create index on 'portfolios.measures_migrated'", CreateIndexOnPortfoliosMeasuresMigrated.class) .add(10_8_006, "Migrate the content of 'live_measures' to 'measures' for portfolios", MigratePortfoliosLiveMeasuresToMeasures.class) .add(10_8_007, "Create primary key on 'measures' table", CreatePrimaryKeyOnMeasuresTable.class) - .add(10_8_008, "Create index on column 'branch_uuid' in 'measures' table", CreateIndexOnMeasuresTable.class); + .add(10_8_008, "Create index on column 'branch_uuid' in 'measures' table", CreateIndexOnMeasuresTable.class) + .add(10_8_009, "Drop column 'from_hotspot' in the 'issues' table", DropColumnFromHotspotInIssues.class); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropColumnFromHotspotInIssues.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropColumnFromHotspotInIssues.java new file mode 100644 index 00000000000..bb30891e5d9 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropColumnFromHotspotInIssues.java @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropColumnChange; + +public class DropColumnFromHotspotInIssues extends DropColumnChange { + private static final String COLUMN_NAME = "from_hotspot"; + private static final String TABLE_NAME = "issues"; + + public DropColumnFromHotspotInIssues(Database db) { + super(db, TABLE_NAME, COLUMN_NAME); + } +} -- 2.39.5