mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -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:
2804
util/PostgresMigrations/Migrations/20240909133245_NotificationCenter.Designer.cs
generated
Normal file
2804
util/PostgresMigrations/Migrations/20240909133245_NotificationCenter.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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");
|
||||
}
|
||||
}
|
@ -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")
|
||||
|
Reference in New Issue
Block a user