mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
[PM-14590] Modify Notification database table (#5361)
* Added notification type enum Added option type to entity * created migration files * made sprocs backward compatible * made sprocs backward compatible * Fixed linting * Altered table to require an optional taskId * formatted code * Added foreignkey * Formatted code * fixed order
This commit is contained in:
@ -0,0 +1,107 @@
|
||||
-- Add optional TaskId column to Notification table
|
||||
IF COL_LENGTH('[dbo].[Notification]', 'TaskId') IS NULL
|
||||
BEGIN
|
||||
ALTER TABLE [dbo].[Notification]
|
||||
ADD [TaskId] UNIQUEIDENTIFIER NULL
|
||||
|
||||
ALTER TABLE [dbo].[Notification]
|
||||
ADD CONSTRAINT [FK_Notification_SecurityTask] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[SecurityTask] ([Id])
|
||||
END
|
||||
GO
|
||||
|
||||
IF NOT EXISTS (SELECT *
|
||||
FROM sys.indexes
|
||||
WHERE name = 'IX_Notification_TaskId')
|
||||
BEGIN
|
||||
CREATE NONCLUSTERED INDEX [IX_Notification_TaskId]
|
||||
ON [dbo].[Notification] ([TaskId] ASC) WHERE TaskId IS NOT NULL;
|
||||
END
|
||||
GO
|
||||
|
||||
-- Alter Notification_Create and Notification_Update stored procedures to include TaskId
|
||||
CREATE OR ALTER PROCEDURE [dbo].[Notification_Create]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@Priority TINYINT,
|
||||
@Global BIT,
|
||||
@ClientType TINYINT,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Title NVARCHAR(256),
|
||||
@Body NVARCHAR(MAX),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7),
|
||||
@TaskId UNIQUEIDENTIFIER = NULL
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[Notification] (
|
||||
[Id],
|
||||
[Priority],
|
||||
[Global],
|
||||
[ClientType],
|
||||
[UserId],
|
||||
[OrganizationId],
|
||||
[Title],
|
||||
[Body],
|
||||
[CreationDate],
|
||||
[RevisionDate],
|
||||
[TaskId]
|
||||
)
|
||||
VALUES (
|
||||
@Id,
|
||||
@Priority,
|
||||
@Global,
|
||||
@ClientType,
|
||||
@UserId,
|
||||
@OrganizationId,
|
||||
@Title,
|
||||
@Body,
|
||||
@CreationDate,
|
||||
@RevisionDate,
|
||||
@TaskId
|
||||
)
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE OR ALTER PROCEDURE [dbo].[Notification_Update]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@Priority TINYINT,
|
||||
@Global BIT,
|
||||
@ClientType TINYINT,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Title NVARCHAR(256),
|
||||
@Body NVARCHAR(MAX),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7),
|
||||
@TaskId UNIQUEIDENTIFIER = NULL
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE [dbo].[Notification]
|
||||
SET [Priority] = @Priority,
|
||||
[Global] = @Global,
|
||||
[ClientType] = @ClientType,
|
||||
[UserId] = @UserId,
|
||||
[OrganizationId] = @OrganizationId,
|
||||
[Title] = @Title,
|
||||
[Body] = @Body,
|
||||
[CreationDate] = @CreationDate,
|
||||
[RevisionDate] = @RevisionDate,
|
||||
[TaskId] = @TaskId
|
||||
WHERE [Id] = @Id
|
||||
END
|
||||
GO
|
||||
|
||||
-- Recreate NotificationView
|
||||
CREATE OR ALTER VIEW [dbo].[NotificationView]
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[Notification]
|
||||
GO
|
||||
|
||||
|
3009
util/MySqlMigrations/Migrations/20250207204741_AddOptionalNotificationTaskId.Designer.cs
generated
Normal file
3009
util/MySqlMigrations/Migrations/20250207204741_AddOptionalNotificationTaskId.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,48 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.MySqlMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class AddOptionalNotifificationTaskId : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "TaskId",
|
||||
table: "Notification",
|
||||
type: "char(36)",
|
||||
nullable: true,
|
||||
collation: "ascii_general_ci");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notification_TaskId",
|
||||
table: "Notification",
|
||||
column: "TaskId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Notification_SecurityTask_TaskId",
|
||||
table: "Notification",
|
||||
column: "TaskId",
|
||||
principalTable: "SecurityTask",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Notification_SecurityTask_TaskId",
|
||||
table: "Notification");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Notification_TaskId",
|
||||
table: "Notification");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TaskId",
|
||||
table: "Notification");
|
||||
}
|
||||
}
|
@ -1674,6 +1674,9 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.Property<DateTime>("RevisionDate")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<Guid?>("TaskId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("varchar(256)");
|
||||
@ -1687,6 +1690,9 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.HasIndex("OrganizationId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("TaskId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
@ -2628,12 +2634,18 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
.WithMany()
|
||||
.HasForeignKey("OrganizationId");
|
||||
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.Vault.Models.SecurityTask", "Task")
|
||||
.WithMany()
|
||||
.HasForeignKey("TaskId");
|
||||
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId");
|
||||
|
||||
b.Navigation("Organization");
|
||||
|
||||
b.Navigation("Task");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
|
3015
util/PostgresMigrations/Migrations/20250207204729_AddOptionalNotificationTaskId.Designer.cs
generated
Normal file
3015
util/PostgresMigrations/Migrations/20250207204729_AddOptionalNotificationTaskId.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,47 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.PostgresMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class AddOptionalNotifificationTaskId : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "TaskId",
|
||||
table: "Notification",
|
||||
type: "uuid",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notification_TaskId",
|
||||
table: "Notification",
|
||||
column: "TaskId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Notification_SecurityTask_TaskId",
|
||||
table: "Notification",
|
||||
column: "TaskId",
|
||||
principalTable: "SecurityTask",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Notification_SecurityTask_TaskId",
|
||||
table: "Notification");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Notification_TaskId",
|
||||
table: "Notification");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TaskId",
|
||||
table: "Notification");
|
||||
}
|
||||
}
|
@ -1680,6 +1680,9 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.Property<DateTime>("RevisionDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid?>("TaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
@ -1693,6 +1696,9 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.HasIndex("OrganizationId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("TaskId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
@ -2634,12 +2640,18 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
.WithMany()
|
||||
.HasForeignKey("OrganizationId");
|
||||
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.Vault.Models.SecurityTask", "Task")
|
||||
.WithMany()
|
||||
.HasForeignKey("TaskId");
|
||||
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId");
|
||||
|
||||
b.Navigation("Organization");
|
||||
|
||||
b.Navigation("Task");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
|
2998
util/SqliteMigrations/Migrations/20250207204735_AddOptionalNotificationTaskId.Designer.cs
generated
Normal file
2998
util/SqliteMigrations/Migrations/20250207204735_AddOptionalNotificationTaskId.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,47 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.SqliteMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class AddOptionalNotifificationTaskId : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "TaskId",
|
||||
table: "Notification",
|
||||
type: "TEXT",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notification_TaskId",
|
||||
table: "Notification",
|
||||
column: "TaskId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Notification_SecurityTask_TaskId",
|
||||
table: "Notification",
|
||||
column: "TaskId",
|
||||
principalTable: "SecurityTask",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Notification_SecurityTask_TaskId",
|
||||
table: "Notification");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Notification_TaskId",
|
||||
table: "Notification");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TaskId",
|
||||
table: "Notification");
|
||||
}
|
||||
}
|
@ -1663,6 +1663,9 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.Property<DateTime>("RevisionDate")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid?>("TaskId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("TEXT");
|
||||
@ -1676,6 +1679,9 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.HasIndex("OrganizationId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("TaskId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
@ -2617,12 +2623,18 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
.WithMany()
|
||||
.HasForeignKey("OrganizationId");
|
||||
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.Vault.Models.SecurityTask", "Task")
|
||||
.WithMany()
|
||||
.HasForeignKey("TaskId");
|
||||
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId");
|
||||
|
||||
b.Navigation("Organization");
|
||||
|
||||
b.Navigation("Task");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user