aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2022-03-29 16:20:40 -0500
committersonartech <sonartech@sonarsource.com>2022-04-01 08:22:58 +0000
commitdc84e9f271f4a72de0b55c0cfd141bf67e1ddeb8 (patch)
tree53d489c0daf9151261fcab862bd6ba23020e3697 /server/sonar-db-migration
parentd27e2321560f15d7d5a59e1c99c80891d7632bdd (diff)
downloadsonarqube-dc84e9f271f4a72de0b55c0cfd141bf67e1ddeb8.tar.gz
sonarqube-dc84e9f271f4a72de0b55c0cfd141bf67e1ddeb8.zip
SONAR-16139 Drop api/users/set_setting and related db table
Diffstat (limited to 'server/sonar-db-migration')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DbVersion94.java1
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropUserPropertiesTable.java47
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropUserPropertiesTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropUserPropertiesTableTest/schema.sql9
4 files changed, 107 insertions, 0 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DbVersion94.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DbVersion94.java
index 818ed58e6fe..a5e675aecbe 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DbVersion94.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DbVersion94.java
@@ -31,6 +31,7 @@ public class DbVersion94 implements DbVersion {
.add(6303, "Drop unused Issues Column ISSUE_ATTRIBUTES", DropIssuesAttributesIssueColumn.class)
.add(6304, "Create table 'SCANNER_ANALYSIS_CACHE", CreateScannerAnalysisCacheTable.class)
.add(6305, "Issue warning for users using SHA1 hash method", SelectUsersWithSha1HashMethod.class)
+ .add(6306, "Drop table 'user_properties'", DropUserPropertiesTable.class)
;
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropUserPropertiesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropUserPropertiesTable.java
new file mode 100644
index 00000000000..625001b29b0
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropUserPropertiesTable.java
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.v94;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.DropTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropUserPropertiesTable extends DdlChange {
+ private static final String TABLE_NAME = "user_properties";
+
+ public DropUserPropertiesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (tableExists()) {
+ context.execute(new DropTableBuilder(getDialect(), TABLE_NAME).build());
+ }
+ }
+
+ private boolean tableExists() throws SQLException {
+ try (var connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.tableExists(TABLE_NAME, connection);
+ }
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropUserPropertiesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropUserPropertiesTableTest.java
new file mode 100644
index 00000000000..7827ca81cb2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropUserPropertiesTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.v94;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class DropUserPropertiesTableTest {
+ private static final String TABLE_NAME = "user_properties";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(DropUserPropertiesTableTest.class, "schema.sql");
+
+ private final DropUserPropertiesTable underTest = new DropUserPropertiesTable(db.database());
+
+ @Test
+ public void migration_should_drop_table() throws SQLException {
+ db.assertTableExists(TABLE_NAME);
+ underTest.execute();
+ db.assertTableDoesNotExist(TABLE_NAME);
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ db.assertTableExists(TABLE_NAME);
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+ db.assertTableDoesNotExist(TABLE_NAME);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropUserPropertiesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropUserPropertiesTableTest/schema.sql
new file mode 100644
index 00000000000..47d627d4561
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropUserPropertiesTableTest/schema.sql
@@ -0,0 +1,9 @@
+CREATE TABLE "USER_PROPERTIES"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "USER_UUID" CHARACTER VARYING(255) NOT NULL,
+ "KEE" CHARACTER VARYING(100) NOT NULL,
+ "TEXT_VALUE" CHARACTER VARYING(4000) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "USER_PROPERTIES" ADD CONSTRAINT "PK_USER_PROPERTIES" PRIMARY KEY("UUID");