]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20156 Make project_uuid nullable in user_dismissed_messages
authorNolwenn Cadic <nolwenn.cadic@sonarsource.com>
Tue, 15 Aug 2023 15:40:11 +0000 (17:40 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 24 Aug 2023 20:03:06 +0000 (20:03 +0000)
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessages.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesTest/schema.sql [new file with mode: 0644]

index 1d99f362b294ccb3c4171052032f3e632da12bf6..7944ece37b2897fa9d2252feadc88702413eddeb 100644 (file)
@@ -1023,7 +1023,7 @@ CREATE INDEX "SNAPSHOTS_ROOT_COMPONENT_UUID" ON "SNAPSHOTS"("ROOT_COMPONENT_UUID
 CREATE TABLE "USER_DISMISSED_MESSAGES"(
     "UUID" CHARACTER VARYING(40) NOT NULL,
     "USER_UUID" CHARACTER VARYING(255) NOT NULL,
-    "PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
+    "PROJECT_UUID" CHARACTER VARYING(40),
     "MESSAGE_TYPE" CHARACTER VARYING(255) NOT NULL,
     "CREATED_AT" BIGINT NOT NULL
 );
index 58a9a59067c23286d102b242c5ce2fb2c7443105..c988d839b0a14f87643ad8e13542bf9c6d63bc91 100644 (file)
@@ -99,6 +99,7 @@ public class DbVersion102 implements DbVersion {
       .add(10_2_042, "Create table 'github_orgs_groups'", CreateGithubOrganizationsGroupsTable.class)
       .add(10_2_043, "Create 'previous_non_compliant_value' in 'new_code_periods' table", CreatePreviousNonCompliantValueInNewCodePeriods.class)
       .add(10_2_044, "Update column 'value' and populate column 'previous_non_compliant_value' in 'new_code_periods' table",
-        UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriods.class);
+        UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriods.class)
+      .add(10_2_045, "Alter 'project_uuid' in 'user_dismissed_messages' - make it nullable", MakeProjectUuidNullableInUserDismissedMessages.class);
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessages.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessages.java
new file mode 100644 (file)
index 0000000..0cfc56d
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class MakeProjectUuidNullableInUserDismissedMessages extends DdlChange {
+
+  private static final String TABLE_NAME = "user_dismissed_messages";
+  private static final String COLUMN_NAME = "project_uuid";
+
+  public MakeProjectUuidNullableInUserDismissedMessages(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(DdlChange.Context context) throws SQLException {
+    VarcharColumnDef newColumnDef = new VarcharColumnDef.Builder()
+      .setColumnName(COLUMN_NAME)
+      .setIsNullable(true)
+      .setLimit(40)
+      .build();
+    context.execute(new AlterColumnsBuilder(getDialect(), TABLE_NAME).updateColumn(newColumnDef).build());
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesTest.java
new file mode 100644 (file)
index 0000000..3ed3ab2
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import static java.sql.Types.VARCHAR;
+
+public class MakeProjectUuidNullableInUserDismissedMessagesTest {
+
+  private static final String TABLE_NAME = "user_dismissed_messages";
+  private static final String COLUMN_NAME = "project_uuid";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(MakeProjectUuidNullableInUserDismissedMessagesTest.class, "schema.sql");
+
+  private final MakeProjectUuidNullableInUserDismissedMessages underTest = new MakeProjectUuidNullableInUserDismissedMessages(db.database());
+
+  @Test
+  public void execute_shouldBeNullable() throws SQLException {
+    db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, false);
+    underTest.execute();
+    db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, true);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, false);
+    underTest.execute();
+    underTest.execute();
+
+    db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, true);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesTest/schema.sql
new file mode 100644 (file)
index 0000000..aa1795f
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "USER_DISMISSED_MESSAGES"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "USER_UUID" CHARACTER VARYING(255) NOT NULL,
+    "PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
+    "MESSAGE_TYPE" CHARACTER VARYING(255) NOT NULL,
+    "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "USER_DISMISSED_MESSAGES" ADD CONSTRAINT "PK_USER_DISMISSED_MESSAGES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_USER_DISMISSED_MESSAGES" ON "USER_DISMISSED_MESSAGES"("USER_UUID" NULLS FIRST, "PROJECT_UUID" NULLS FIRST, "MESSAGE_TYPE" NULLS FIRST);
+CREATE INDEX "UDM_PROJECT_UUID" ON "USER_DISMISSED_MESSAGES"("PROJECT_UUID" NULLS FIRST);
+CREATE INDEX "UDM_MESSAGE_TYPE" ON "USER_DISMISSED_MESSAGES"("MESSAGE_TYPE" NULLS FIRST);
\ No newline at end of file