From: Jacek <52388493+jacek-poreda-sonarsource@users.noreply.github.com> Date: Tue, 20 Aug 2019 13:07:12 +0000 (+0200) Subject: SONAR-8115 - remove default quality gate from Properties table (#1980) X-Git-Tag: 8.0~216 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=24179ab9a7a429befcc822a5a0ba6afe82721213;p=sonarqube.git SONAR-8115 - remove default quality gate from Properties table (#1980) * SONAR-8115 - remove default quality gate from Properties table --- diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80.java index 71f1748e51d..690b50eaa56 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80.java @@ -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 index 00000000000..39d6dbfd086 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTable.java @@ -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(); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80Test.java index 2ce869795bc..ec96f262c52 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80Test.java @@ -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 index 00000000000..863d4caf6e2 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTableTest.java @@ -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 index 00000000000..d84c238cd48 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTableTest/schema.sql @@ -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");