* SONAR-8115 - remove default quality gate from Properties tabletags/8.0
@@ -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) | |||
; | |||
} | |||
} |
@@ -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(); | |||
} | |||
} |
@@ -35,7 +35,7 @@ public class DbVersion80Test { | |||
@Test | |||
public void verify_migration_count() { | |||
verifyMigrationCount(underTest, 5); | |||
verifyMigrationCount(underTest, 6); | |||
} | |||
} |
@@ -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()); | |||
} | |||
} |
@@ -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"); |