aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2020-08-14 10:17:26 +0200
committersonartech <sonartech@sonarsource.com>2020-08-14 20:16:18 +0000
commitdc7916a368d0b9402cb3ad052b9af9b7d293a748 (patch)
tree6bf10755c02798f033059629b5276bc54a61aa92 /server/sonar-db-migration
parentdf64c184d1427f74592459b42093e8b0b6878c98 (diff)
downloadsonarqube-dc7916a368d0b9402cb3ad052b9af9b7d293a748.tar.gz
sonarqube-dc7916a368d0b9402cb3ad052b9af9b7d293a748.zip
SONAR-11595 drop unused 'value_warning', 'period' columns from 'quality_gate_conditions' table
Diffstat (limited to 'server/sonar-db-migration')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java3
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTable.java37
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTableTest/schema.sql12
4 files changed, 101 insertions, 1 deletions
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");