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
);
.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);
}
}
--- /dev/null
+/*
+ * 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());
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+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