From: Jacek Date: Fri, 14 Aug 2020 08:17:26 +0000 (+0200) Subject: SONAR-11595 drop unused 'value_warning', 'period' columns from 'quality_gate_conditio... X-Git-Tag: 8.5.0.37579~158 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dc7916a368d0b9402cb3ad052b9af9b7d293a748;p=sonarqube.git SONAR-11595 drop unused 'value_warning', 'period' columns from 'quality_gate_conditions' table --- diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index f6ee2bfd5ab..594cb26a21f 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -772,10 +772,8 @@ CREATE INDEX "QPROFILE_EDIT_USERS_QPROFILE" ON "QPROFILE_EDIT_USERS"("QPROFILE_U CREATE UNIQUE INDEX "QPROFILE_EDIT_USERS_UNIQUE" ON "QPROFILE_EDIT_USERS"("USER_UUID", "QPROFILE_UUID"); CREATE TABLE "QUALITY_GATE_CONDITIONS"( - "PERIOD" INTEGER, "OPERATOR" VARCHAR(3), "VALUE_ERROR" VARCHAR(64), - "VALUE_WARNING" VARCHAR(64), "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP, "UUID" VARCHAR(40) NOT NULL, diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java index 3945b46b195..d9d78d829db 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java @@ -26,6 +26,7 @@ public class DbVersion85 implements DbVersion { @Override public void addSteps(MigrationStepRegistry registry) { registry - .add(4000, "Delete 'project_alm_settings' orphans", DeleteProjectAlmSettingsOrphans.class); + .add(4000, "Delete 'project_alm_settings' orphans", DeleteProjectAlmSettingsOrphans.class) + .add(4001, "Drop 'period', 'value_warning' columns from 'quality_gates_conditions' table", DropPeriodAndValueWarningColumnsFromQualityGateConditionsTable.class); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTable.java new file mode 100644 index 00000000000..77e93968d11 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTable.java @@ -0,0 +1,37 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v85; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropPeriodAndValueWarningColumnsFromQualityGateConditionsTable extends DdlChange { + + public DropPeriodAndValueWarningColumnsFromQualityGateConditionsTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropColumnsBuilder(getDialect(), "quality_gate_conditions", "value_warning", "period").build()); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTableTest.java new file mode 100644 index 00000000000..5804d9e5e9b --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTableTest.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v85; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +import static java.sql.Types.INTEGER; +import static java.sql.Types.VARCHAR; + +public class DropPeriodAndValueWarningColumnsFromQualityGateConditionsTableTest { + + private static final String TABLE_NAME = "quality_gate_conditions"; + private static final String COLUMN_NAME_PERIOD = "period"; + private static final String COLUMN_NAME_VALUE_WARNING = "value_warning"; + + @Rule + public CoreDbTester dbTester = CoreDbTester.createForSchema(DropPeriodAndValueWarningColumnsFromQualityGateConditionsTableTest.class, "schema.sql"); + + private DropPeriodAndValueWarningColumnsFromQualityGateConditionsTable underTest = new DropPeriodAndValueWarningColumnsFromQualityGateConditionsTable(dbTester.database()); + + @Test + public void column_has_been_dropped() throws SQLException { + dbTester.assertColumnDefinition(TABLE_NAME, COLUMN_NAME_PERIOD, INTEGER, null, true); + dbTester.assertColumnDefinition(TABLE_NAME, COLUMN_NAME_VALUE_WARNING, VARCHAR, null, true); + underTest.execute(); + dbTester.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME_PERIOD); + dbTester.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME_VALUE_WARNING); + } + +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTableTest/schema.sql new file mode 100644 index 00000000000..53249a51cc0 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTableTest/schema.sql @@ -0,0 +1,12 @@ +CREATE TABLE "QUALITY_GATE_CONDITIONS"( + "PERIOD" INTEGER, + "OPERATOR" VARCHAR(3), + "VALUE_ERROR" VARCHAR(64), + "VALUE_WARNING" VARCHAR(64), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP, + "UUID" VARCHAR(40) NOT NULL, + "METRIC_UUID" VARCHAR(40) NOT NULL, + "QGATE_UUID" VARCHAR(40) NOT NULL +); +ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID");