]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8115 - remove default quality gate from Properties table (#1980)
authorJacek <52388493+jacek-poreda-sonarsource@users.noreply.github.com>
Tue, 20 Aug 2019 13:07:12 +0000 (15:07 +0200)
committerSonarTech <sonartech@sonarsource.com>
Tue, 20 Aug 2019 18:21:03 +0000 (20:21 +0200)
* SONAR-8115 - remove default quality gate from Properties table

server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTableTest/schema.sql [new file with mode: 0644]

index 71f1748e51d20585a9357301bceaab18d88eb5e7..690b50eaa56910c51b62d7907bcd1d1487377d33 100644 (file)
@@ -31,6 +31,7 @@ public class DbVersion80 implements DbVersion {
       .add(3002, "Make index on DEPRECATED_RULE_KEYS.RULE_ID non unique", MakeDeprecatedRuleKeysRuleIdIndexNonUnique.class)
       .add(3003, "Populate ProjectQualityGate table from Properties table", PopulateProjectQualityGatesTable.class)
       .add(3004, "Rename ANALYSIS_PROPERTIES.SNAPSHOT_UUID to ANALYSIS_UUID", RenameAnalysisPropertiesSnapshotUuid.class)
+      .add(3005, "Remove default quality gate property from Properties table", RemoveDefaultQualityGateFromPropertiesTable.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTable.java
new file mode 100644 (file)
index 0000000..39d6dbf
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.v80;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+public class RemoveDefaultQualityGateFromPropertiesTable extends DataChange {
+
+  public RemoveDefaultQualityGateFromPropertiesTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  protected void execute(Context context) throws SQLException {
+    context.prepareUpsert("delete from properties where prop_key='sonar.qualitygate'")
+      .execute()
+      .commit();
+  }
+
+}
index 2ce869795bc9090791a559174a669a3f900ca559..ec96f262c520bef6d6e7548c0db04e5461cb7297 100644 (file)
@@ -35,7 +35,7 @@ public class DbVersion80Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 5);
+    verifyMigrationCount(underTest, 6);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTableTest.java
new file mode 100644 (file)
index 0000000..863d4ca
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.v80;
+
+import java.sql.SQLException;
+import java.time.Instant;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+
+public class RemoveDefaultQualityGateFromPropertiesTableTest {
+  private static final String PROPERTIES_TABLE_NAME = "properties";
+  private static final int TOTAL_NUMBER_OF_PROPERTIES = 10;
+
+  @Rule
+  public CoreDbTester dbTester = CoreDbTester.createForSchema(RemoveDefaultQualityGateFromPropertiesTableTest.class, "schema.sql");
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private RemoveDefaultQualityGateFromPropertiesTable underTest = new RemoveDefaultQualityGateFromPropertiesTable(dbTester.database());
+
+  @Test
+  public void remove_default_quality_gate_property() throws SQLException {
+    for (long i = 1; i <= TOTAL_NUMBER_OF_PROPERTIES; i++) {
+      insertQualityGateProperty(i, i + 100);
+    }
+
+    int propertiesCount = dbTester.countRowsOfTable(PROPERTIES_TABLE_NAME);
+    Assert.assertEquals(TOTAL_NUMBER_OF_PROPERTIES, propertiesCount);
+
+    underTest.execute();
+
+    //should delete properties
+    propertiesCount = dbTester.countRowsOfTable(PROPERTIES_TABLE_NAME);
+    Assert.assertEquals(0, propertiesCount);
+
+    //should not fail if executed twice
+    underTest.execute();
+  }
+
+  private void insertQualityGateProperty(Long projectId, Long qualityGateId) {
+    dbTester.executeInsert(PROPERTIES_TABLE_NAME,
+      "prop_key", "sonar.qualitygate",
+      "resource_id", projectId,
+      "is_empty", false,
+      "text_value", Long.toString(qualityGateId),
+      "created_at", Instant.now().toEpochMilli());
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..d84c238
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "PROPERTIES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "PROP_KEY" VARCHAR(512) NOT NULL,
+  "RESOURCE_ID" INTEGER,
+  "USER_ID" INTEGER,
+  "IS_EMPTY" BOOLEAN NOT NULL,
+  "TEXT_VALUE" VARCHAR(4000),
+  "CLOB_VALUE" CLOB,
+  "CREATED_AT" BIGINT
+);
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES" ("PROP_KEY");