.add(1834, "Set WEBHOOK_DELIVERIES.CE_TASK_UUID as nullable", UpdateCeTaskUuidColumnToNullableOnWebhookDeliveries.class)
.add(1835, "Populate WEBHOOK_DELIVERIES.ANALYSIS_UUID", PopulateAnalysisUuidColumnOnWebhookDeliveries.class)
.add(1836, "Migrate 'previous_analysis' leak periods to 'previous_version'", MigratePreviousAnalysisToPreviousVersion.class)
+ .add(1837, "Drop old licenses", DropOldLicenses.class)
;
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.v67;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class DropOldLicenses extends DataChange {
+
+ private static final String LICENSE_HASH_SECURED_SUFFIX = ".licenseHash.secured";
+ private static final String LICENSE_SECURED_SUFFIX = ".license.secured";
+
+ public DropOldLicenses(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select("select prop_key from properties where prop_key like ?")
+ .setString(1, "%" + LICENSE_HASH_SECURED_SUFFIX);
+ massUpdate.update("delete from properties where prop_key = ? or prop_key = ?");
+ massUpdate.rowPluralName("old license properties");
+ massUpdate.execute((row, update) -> {
+ String licenseHashKey = row.getString(1);
+ String licenseKey = licenseHashKey.replace(LICENSE_HASH_SECURED_SUFFIX, "") + LICENSE_SECURED_SUFFIX;
+ update.setString(1, licenseHashKey);
+ update.setString(2, licenseKey);
+ return true;
+ });
+ }
+}
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 7);
+ verifyMigrationCount(underTest, 8);
}
}
--- /dev/null
+package org.sonar.server.platform.db.migration.version.v67;
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.
+ */
+
+import java.sql.SQLException;
+import java.util.stream.Collectors;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DropOldLicensesTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropOldLicensesTest.class, "properties.sql");
+
+ private DropOldLicenses underTest = new DropOldLicenses(db.database());
+
+ @Test
+ public void remove_old_licenses() throws SQLException {
+ insertProperty("sonar.cpp.license.secured");
+ insertProperty("sonar.cpp.licenseHash.secured");
+ insertProperty("sonar.objc.license.secured");
+ insertProperty("sonar.objc.licenseHash.secured");
+
+ underTest.execute();
+
+ assertPropertiesIsEmpty();
+ }
+
+ @Test
+ public void ignore_existing_none_related_licenses_settings() throws SQLException {
+ insertProperty("my.property");
+ insertProperty("custom.license");
+
+ underTest.execute();
+
+ assertProperties("my.property", "custom.license");
+ }
+
+ private void assertPropertiesIsEmpty() {
+ assertProperties();
+ }
+
+ private void assertProperties(String... expectedSettingKeys) {
+ assertThat(db.select("SELECT PROP_KEY FROM PROPERTIES")
+ .stream()
+ .map(map -> map.get("PROP_KEY"))
+ .collect(Collectors.toList()))
+ .containsExactlyInAnyOrder(expectedSettingKeys);
+ }
+
+ public void insertProperty(String propertyKey) {
+ db.executeInsert(
+ "properties",
+ "prop_key", propertyKey,
+ "is_empty", "false",
+ "text_value", randomAlphabetic(2));
+ }
+
+}
--- /dev/null
+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(2147483647),
+ "CREATED_AT" BIGINT
+);
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES" ("PROP_KEY");