1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 23:52:50 -05:00

[PM-10560] Create notification database storage (#4688)

* Add new tables

* Add stored procedures

* Add core entities and models

* Setup EF

* Add repository interfaces

* Add dapper repos

* Add EF repos

* Add order by

* EF updates

* PM-10560: Notifications repository matching requirements.

* PM-10560: Notifications repository matching requirements.

* PM-10560: Migration scripts

* PM-10560: EF index optimizations

* PM-10560: Cleanup

* PM-10560: Priority in natural order, Repository, sql simplifications

* PM-10560: Title column update

* PM-10560: Incorrect EF migration removal

* PM-10560: EF migrations

* PM-10560: Added views, SP naming simplification

* PM-10560: Notification entity Title update, EF migrations

* PM-10560: Removing Notification_ReadByUserId

* PM-10560: Notification ReadByUserIdAndStatus fix

* PM-10560: Notification ReadByUserIdAndStatus fix to be in line with requirements and EF

---------

Co-authored-by: Maciej Zieniuk <mzieniuk@bitwarden.com>
Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
This commit is contained in:
Thomas Avery
2024-09-09 14:52:12 -05:00
committed by GitHub
parent 55bf815050
commit 4c0f8d54f3
39 changed files with 9983 additions and 0 deletions

View File

@ -0,0 +1,295 @@
-- Notification
-- Table Notification
IF OBJECT_ID('[dbo].[Notification]') IS NULL
BEGIN
CREATE TABLE [dbo].[Notification]
(
[Id] UNIQUEIDENTIFIER NOT NULL,
[Priority] TINYINT NOT NULL,
[Global] BIT NOT NULL,
[ClientType] TINYINT NOT NULL,
[UserId] UNIQUEIDENTIFIER NULL,
[OrganizationId] UNIQUEIDENTIFIER NULL,
[Title] NVARCHAR(256) NULL,
[Body] NVARCHAR(MAX) NULL,
[CreationDate] DATETIME2(7) NOT NULL,
[RevisionDate] DATETIME2(7) NOT NULL,
CONSTRAINT [PK_Notification] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Notification_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]),
CONSTRAINT [FK_Notification_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
);
CREATE NONCLUSTERED INDEX [IX_Notification_Priority_CreationDate_ClientType_Global_UserId_OrganizationId]
ON [dbo].[Notification] ([Priority] DESC, [CreationDate] DESC, [ClientType], [Global], [UserId],
[OrganizationId]);
CREATE NONCLUSTERED INDEX [IX_Notification_UserId]
ON [dbo].[Notification] ([UserId] ASC) WHERE UserId IS NOT NULL;
CREATE NONCLUSTERED INDEX [IX_Notification_OrganizationId]
ON [dbo].[Notification] ([OrganizationId] ASC) WHERE OrganizationId IS NOT NULL;
END
GO
-- Table NotificationStatus
IF OBJECT_ID('[dbo].[NotificationStatus]') IS NULL
BEGIN
CREATE TABLE [dbo].[NotificationStatus]
(
[NotificationId] UNIQUEIDENTIFIER NOT NULL,
[UserId] UNIQUEIDENTIFIER NOT NULL,
[ReadDate] DATETIME2(7) NULL,
[DeletedDate] DATETIME2(7) NULL,
CONSTRAINT [PK_NotificationStatus] PRIMARY KEY CLUSTERED ([NotificationId] ASC, [UserId] ASC),
CONSTRAINT [FK_NotificationStatus_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
);
END
GO
-- View Notification
IF EXISTS(SELECT *
FROM sys.views
WHERE [Name] = 'NotificationView')
BEGIN
DROP VIEW [dbo].[NotificationView]
END
GO
CREATE VIEW [dbo].[NotificationView]
AS
SELECT *
FROM [dbo].[Notification]
GO
-- View NotificationStatus
IF EXISTS(SELECT *
FROM sys.views
WHERE [Name] = 'NotificationStatusView')
BEGIN
DROP VIEW [dbo].[NotificationStatusView]
END
GO
CREATE VIEW [dbo].[NotificationStatusView]
AS
SELECT *
FROM [dbo].[NotificationStatus]
GO
-- Stored Procedures: Create
IF OBJECT_ID('[dbo].[Notification_Create]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[Notification_Create]
END
GO
CREATE 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)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[Notification] ([Id],
[Priority],
[Global],
[ClientType],
[UserId],
[OrganizationId],
[Title],
[Body],
[CreationDate],
[RevisionDate])
VALUES (@Id,
@Priority,
@Global,
@ClientType,
@UserId,
@OrganizationId,
@Title,
@Body,
@CreationDate,
@RevisionDate)
END
GO
-- Stored Procedure: ReadById
IF OBJECT_ID('[dbo].[Notification_ReadById]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[Notification_ReadById]
END
GO
CREATE PROCEDURE [dbo].[Notification_ReadById] @Id UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
SELECT *
FROM [dbo].[NotificationView]
WHERE [Id] = @Id
END
GO
-- Stored Procedure: ReadByUserIdAndStatus
IF OBJECT_ID('[dbo].[Notification_ReadByUserIdAndStatus]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[Notification_ReadByUserIdAndStatus]
END
GO
CREATE PROCEDURE [dbo].[Notification_ReadByUserIdAndStatus]
@UserId UNIQUEIDENTIFIER,
@ClientType TINYINT,
@Read BIT,
@Deleted BIT
AS
BEGIN
SET NOCOUNT ON
SELECT n.*
FROM [dbo].[NotificationView] n
LEFT JOIN [dbo].[OrganizationUserView] ou ON n.[OrganizationId] = ou.[OrganizationId]
AND ou.[UserId] = @UserId
LEFT JOIN [dbo].[NotificationStatusView] ns ON n.[Id] = ns.[NotificationId]
AND ns.[UserId] = @UserId
WHERE [ClientType] IN (0, CASE WHEN @ClientType != 0 THEN @ClientType END)
AND ([Global] = 1
OR (n.[UserId] = @UserId
AND (n.[OrganizationId] IS NULL
OR ou.[OrganizationId] IS NOT NULL))
OR (n.[UserId] IS NULL
AND ou.[OrganizationId] IS NOT NULL))
AND ((@Read IS NULL AND @Deleted IS NULL)
OR (ns.[NotificationId] IS NOT NULL
AND ((@Read IS NULL
OR IIF((@Read = 1 AND ns.[ReadDate] IS NOT NULL) OR
(@Read = 0 AND ns.[ReadDate] IS NULL),
1, 0) = 1)
OR (@Deleted IS NULL
OR IIF((@Deleted = 1 AND ns.[DeletedDate] IS NOT NULL) OR
(@Deleted = 0 AND ns.[DeletedDate] IS NULL),
1, 0) = 1))))
ORDER BY [Priority] DESC, n.[CreationDate] DESC
END
GO
-- Stored Procedure: Update
IF OBJECT_ID('[dbo].[Notification_Update]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[Notification_Update]
END
GO
CREATE 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)
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
WHERE [Id] = @Id
END
GO
-- NotificationStatus
-- Stored Procedure: Create
IF OBJECT_ID('[dbo].[NotificationStatus_Create]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[NotificationStatus_Create]
END
GO
CREATE PROCEDURE [dbo].[NotificationStatus_Create]
@NotificationId UNIQUEIDENTIFIER,
@UserId UNIQUEIDENTIFIER,
@ReadDate DATETIME2(7),
@DeletedDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[NotificationStatus] ([NotificationId],
[UserId],
[ReadDate],
[DeletedDate])
VALUES (@NotificationId,
@UserId,
@ReadDate,
@DeletedDate)
END
GO
-- Stored Procedure: ReadByNotificationIdAndUserId
IF OBJECT_ID('[dbo].[NotificationStatus_ReadByNotificationIdAndUserId]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[NotificationStatus_ReadByNotificationIdAndUserId]
END
GO
CREATE PROCEDURE [dbo].[NotificationStatus_ReadByNotificationIdAndUserId]
@NotificationId UNIQUEIDENTIFIER,
@UserId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
SELECT TOP 1 *
FROM [dbo].[NotificationStatusView]
WHERE [NotificationId] = @NotificationId
AND [UserId] = @UserId
END
GO
-- Stored Procedure: Update
IF OBJECT_ID('[dbo].[NotificationStatus_Update]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[NotificationStatus_Update]
END
GO
CREATE PROCEDURE [dbo].[NotificationStatus_Update]
@NotificationId UNIQUEIDENTIFIER,
@UserId UNIQUEIDENTIFIER,
@ReadDate DATETIME2(7),
@DeletedDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
UPDATE [dbo].[NotificationStatus]
SET [ReadDate] = @ReadDate,
[DeletedDate] = @DeletedDate
WHERE [NotificationId] = @NotificationId
AND [UserId] = @UserId
END
GO

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,104 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.MySqlMigrations.Migrations;
/// <inheritdoc />
public partial class NotificationCenter : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Notification",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
Priority = table.Column<byte>(type: "tinyint unsigned", nullable: false),
Global = table.Column<bool>(type: "tinyint(1)", nullable: false),
ClientType = table.Column<byte>(type: "tinyint unsigned", nullable: false),
UserId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
OrganizationId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
Title = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Body = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
CreationDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
RevisionDate = table.Column<DateTime>(type: "datetime(6)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Notification", x => x.Id);
table.ForeignKey(
name: "FK_Notification_Organization_OrganizationId",
column: x => x.OrganizationId,
principalTable: "Organization",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Notification_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id");
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "NotificationStatus",
columns: table => new
{
NotificationId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
UserId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
ReadDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
DeletedDate = table.Column<DateTime>(type: "datetime(6)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_NotificationStatus", x => new { x.UserId, x.NotificationId });
table.ForeignKey(
name: "FK_NotificationStatus_Notification_NotificationId",
column: x => x.NotificationId,
principalTable: "Notification",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_NotificationStatus_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_Notification_ClientType_Global_UserId_OrganizationId_Priorit~",
table: "Notification",
columns: new[] { "ClientType", "Global", "UserId", "OrganizationId", "Priority", "CreationDate" },
descending: new[] { false, false, false, false, true, true });
migrationBuilder.CreateIndex(
name: "IX_Notification_OrganizationId",
table: "Notification",
column: "OrganizationId");
migrationBuilder.CreateIndex(
name: "IX_Notification_UserId",
table: "Notification",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_NotificationStatus_NotificationId",
table: "NotificationStatus",
column: "NotificationId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "NotificationStatus");
migrationBuilder.DropTable(
name: "Notification");
}
}

View File

@ -1588,6 +1588,77 @@ namespace Bit.MySqlMigrations.Migrations
b.ToTable("User", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", b =>
{
b.Property<Guid>("Id")
.HasColumnType("char(36)");
b.Property<string>("Body")
.HasColumnType("longtext");
b.Property<byte>("ClientType")
.HasColumnType("tinyint unsigned");
b.Property<DateTime>("CreationDate")
.HasColumnType("datetime(6)");
b.Property<bool>("Global")
.HasColumnType("tinyint(1)");
b.Property<Guid?>("OrganizationId")
.HasColumnType("char(36)");
b.Property<byte>("Priority")
.HasColumnType("tinyint unsigned");
b.Property<DateTime>("RevisionDate")
.HasColumnType("datetime(6)");
b.Property<string>("Title")
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.Property<Guid?>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id")
.HasAnnotation("SqlServer:Clustered", true);
b.HasIndex("OrganizationId")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("UserId")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("ClientType", "Global", "UserId", "OrganizationId", "Priority", "CreationDate")
.IsDescending(false, false, false, false, true, true)
.HasAnnotation("SqlServer:Clustered", false);
b.ToTable("Notification", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.NotificationStatus", b =>
{
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.Property<Guid>("NotificationId")
.HasColumnType("char(36)");
b.Property<DateTime?>("DeletedDate")
.HasColumnType("datetime(6)");
b.Property<DateTime?>("ReadDate")
.HasColumnType("datetime(6)");
b.HasKey("UserId", "NotificationId")
.HasAnnotation("SqlServer:Clustered", true);
b.HasIndex("NotificationId");
b.ToTable("NotificationStatus", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.SecretsManager.Models.AccessPolicy", b =>
{
b.Property<Guid>("Id")
@ -2380,6 +2451,40 @@ namespace Bit.MySqlMigrations.Migrations
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
.WithMany()
.HasForeignKey("OrganizationId");
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("Organization");
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.NotificationStatus", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", "Notification")
.WithMany()
.HasForeignKey("NotificationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Notification");
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.SecretsManager.Models.ApiKey", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.SecretsManager.Models.ServiceAccount", "ServiceAccount")

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,100 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.PostgresMigrations.Migrations;
/// <inheritdoc />
public partial class NotificationCenter : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Notification",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Priority = table.Column<byte>(type: "smallint", nullable: false),
Global = table.Column<bool>(type: "boolean", nullable: false),
ClientType = table.Column<byte>(type: "smallint", nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: true),
OrganizationId = table.Column<Guid>(type: "uuid", nullable: true),
Title = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
Body = table.Column<string>(type: "text", nullable: true),
CreationDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
RevisionDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Notification", x => x.Id);
table.ForeignKey(
name: "FK_Notification_Organization_OrganizationId",
column: x => x.OrganizationId,
principalTable: "Organization",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Notification_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "NotificationStatus",
columns: table => new
{
NotificationId = table.Column<Guid>(type: "uuid", nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
ReadDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
DeletedDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_NotificationStatus", x => new { x.UserId, x.NotificationId });
table.ForeignKey(
name: "FK_NotificationStatus_Notification_NotificationId",
column: x => x.NotificationId,
principalTable: "Notification",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_NotificationStatus_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Notification_ClientType_Global_UserId_OrganizationId_Priori~",
table: "Notification",
columns: new[] { "ClientType", "Global", "UserId", "OrganizationId", "Priority", "CreationDate" },
descending: new[] { false, false, false, false, true, true });
migrationBuilder.CreateIndex(
name: "IX_Notification_OrganizationId",
table: "Notification",
column: "OrganizationId");
migrationBuilder.CreateIndex(
name: "IX_Notification_UserId",
table: "Notification",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_NotificationStatus_NotificationId",
table: "NotificationStatus",
column: "NotificationId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "NotificationStatus");
migrationBuilder.DropTable(
name: "Notification");
}
}

View File

@ -1594,6 +1594,77 @@ namespace Bit.PostgresMigrations.Migrations
b.ToTable("User", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", b =>
{
b.Property<Guid>("Id")
.HasColumnType("uuid");
b.Property<string>("Body")
.HasColumnType("text");
b.Property<byte>("ClientType")
.HasColumnType("smallint");
b.Property<DateTime>("CreationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("Global")
.HasColumnType("boolean");
b.Property<Guid?>("OrganizationId")
.HasColumnType("uuid");
b.Property<byte>("Priority")
.HasColumnType("smallint");
b.Property<DateTime>("RevisionDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Title")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id")
.HasAnnotation("SqlServer:Clustered", true);
b.HasIndex("OrganizationId")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("UserId")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("ClientType", "Global", "UserId", "OrganizationId", "Priority", "CreationDate")
.IsDescending(false, false, false, false, true, true)
.HasAnnotation("SqlServer:Clustered", false);
b.ToTable("Notification", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.NotificationStatus", b =>
{
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.Property<Guid>("NotificationId")
.HasColumnType("uuid");
b.Property<DateTime?>("DeletedDate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("ReadDate")
.HasColumnType("timestamp with time zone");
b.HasKey("UserId", "NotificationId")
.HasAnnotation("SqlServer:Clustered", true);
b.HasIndex("NotificationId");
b.ToTable("NotificationStatus", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.SecretsManager.Models.AccessPolicy", b =>
{
b.Property<Guid>("Id")
@ -2386,6 +2457,40 @@ namespace Bit.PostgresMigrations.Migrations
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
.WithMany()
.HasForeignKey("OrganizationId");
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("Organization");
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.NotificationStatus", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", "Notification")
.WithMany()
.HasForeignKey("NotificationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Notification");
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.SecretsManager.Models.ApiKey", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.SecretsManager.Models.ServiceAccount", "ServiceAccount")

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,100 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.SqliteMigrations.Migrations;
/// <inheritdoc />
public partial class NotificationCenter : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Notification",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
Priority = table.Column<byte>(type: "INTEGER", nullable: false),
Global = table.Column<bool>(type: "INTEGER", nullable: false),
ClientType = table.Column<byte>(type: "INTEGER", nullable: false),
UserId = table.Column<Guid>(type: "TEXT", nullable: true),
OrganizationId = table.Column<Guid>(type: "TEXT", nullable: true),
Title = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true),
Body = table.Column<string>(type: "TEXT", nullable: true),
CreationDate = table.Column<DateTime>(type: "TEXT", nullable: false),
RevisionDate = table.Column<DateTime>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Notification", x => x.Id);
table.ForeignKey(
name: "FK_Notification_Organization_OrganizationId",
column: x => x.OrganizationId,
principalTable: "Organization",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Notification_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "NotificationStatus",
columns: table => new
{
NotificationId = table.Column<Guid>(type: "TEXT", nullable: false),
UserId = table.Column<Guid>(type: "TEXT", nullable: false),
ReadDate = table.Column<DateTime>(type: "TEXT", nullable: true),
DeletedDate = table.Column<DateTime>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_NotificationStatus", x => new { x.UserId, x.NotificationId });
table.ForeignKey(
name: "FK_NotificationStatus_Notification_NotificationId",
column: x => x.NotificationId,
principalTable: "Notification",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_NotificationStatus_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Notification_ClientType_Global_UserId_OrganizationId_Priority_CreationDate",
table: "Notification",
columns: new[] { "ClientType", "Global", "UserId", "OrganizationId", "Priority", "CreationDate" },
descending: new[] { false, false, false, false, true, true });
migrationBuilder.CreateIndex(
name: "IX_Notification_OrganizationId",
table: "Notification",
column: "OrganizationId");
migrationBuilder.CreateIndex(
name: "IX_Notification_UserId",
table: "Notification",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_NotificationStatus_NotificationId",
table: "NotificationStatus",
column: "NotificationId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "NotificationStatus");
migrationBuilder.DropTable(
name: "Notification");
}
}

View File

@ -1577,6 +1577,77 @@ namespace Bit.SqliteMigrations.Migrations
b.ToTable("User", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", b =>
{
b.Property<Guid>("Id")
.HasColumnType("TEXT");
b.Property<string>("Body")
.HasColumnType("TEXT");
b.Property<byte>("ClientType")
.HasColumnType("INTEGER");
b.Property<DateTime>("CreationDate")
.HasColumnType("TEXT");
b.Property<bool>("Global")
.HasColumnType("INTEGER");
b.Property<Guid?>("OrganizationId")
.HasColumnType("TEXT");
b.Property<byte>("Priority")
.HasColumnType("INTEGER");
b.Property<DateTime>("RevisionDate")
.HasColumnType("TEXT");
b.Property<string>("Title")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<Guid?>("UserId")
.HasColumnType("TEXT");
b.HasKey("Id")
.HasAnnotation("SqlServer:Clustered", true);
b.HasIndex("OrganizationId")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("UserId")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("ClientType", "Global", "UserId", "OrganizationId", "Priority", "CreationDate")
.IsDescending(false, false, false, false, true, true)
.HasAnnotation("SqlServer:Clustered", false);
b.ToTable("Notification", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.NotificationStatus", b =>
{
b.Property<Guid>("UserId")
.HasColumnType("TEXT");
b.Property<Guid>("NotificationId")
.HasColumnType("TEXT");
b.Property<DateTime?>("DeletedDate")
.HasColumnType("TEXT");
b.Property<DateTime?>("ReadDate")
.HasColumnType("TEXT");
b.HasKey("UserId", "NotificationId")
.HasAnnotation("SqlServer:Clustered", true);
b.HasIndex("NotificationId");
b.ToTable("NotificationStatus", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.SecretsManager.Models.AccessPolicy", b =>
{
b.Property<Guid>("Id")
@ -2369,6 +2440,40 @@ namespace Bit.SqliteMigrations.Migrations
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
.WithMany()
.HasForeignKey("OrganizationId");
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("Organization");
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.NotificationStatus", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", "Notification")
.WithMany()
.HasForeignKey("NotificationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Notification");
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.SecretsManager.Models.ApiKey", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.SecretsManager.Models.ServiceAccount", "ServiceAccount")