]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11595 drop unused 'value_warning', 'period' columns from 'quality_gate_conditio...
authorJacek <jacek.poreda@sonarsource.com>
Fri, 14 Aug 2020 08:17:26 +0000 (10:17 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 14 Aug 2020 20:16:18 +0000 (20:16 +0000)
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTable.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/DropPeriodAndValueWarningColumnsFromQualityGateConditionsTableTest/schema.sql [new file with mode: 0644]

index f6ee2bfd5ab481cde4ba57c00b413189aac55760..594cb26a21f5397445131372582edbdacee3c1f8 100644 (file)
@@ -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,
index 3945b46b1955d972e3158e677f60955fb9a396d7..d9d78d829dbd96b5c8ce4eb5218b19080d8e5117 100644 (file)
@@ -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 (file)
index 0000000..77e9396
--- /dev/null
@@ -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 (file)
index 0000000..5804d9e
--- /dev/null
@@ -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 (file)
index 0000000..53249a5
--- /dev/null
@@ -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");