From 052b2cf5c567356b7b22507bd7f4a2382ea10550 Mon Sep 17 00:00:00 2001 From: gbubemismith Date: Fri, 7 Feb 2025 15:52:20 -0500 Subject: [PATCH] Added foreignkey --- .../NotificationEntityTypeConfiguration.cs | 4 ++ .../NotificationCenter/Models/Notification.cs | 2 + .../Stored Procedures/Notification_Create.sql | 12 ++--- .../Stored Procedures/Notification_Update.sql | 8 +-- .../dbo/Tables/Notification.sql | 8 ++- ...02-07_00_AddOptionalNotificationTaskId.sql | 36 ++++++++----- ...7182213_AddOptionalNotifificationTaskId.cs | 28 ----------- ...AddOptionalNotificationTaskId.Designer.cs} | 11 +++- ...207204741_AddOptionalNotificationTaskId.cs | 50 +++++++++++++++++++ .../DatabaseContextModelSnapshot.cs | 9 ++++ ...7182206_AddOptionalNotifificationTaskId.cs | 27 ---------- ...AddOptionalNotificationTaskId.Designer.cs} | 11 +++- ...207204729_AddOptionalNotificationTaskId.cs | 49 ++++++++++++++++++ .../DatabaseContextModelSnapshot.cs | 9 ++++ ...7182157_AddOptionalNotifificationTaskId.cs | 27 ---------- ...AddOptionalNotificationTaskId.Designer.cs} | 11 +++- ...207204735_AddOptionalNotificationTaskId.cs | 49 ++++++++++++++++++ .../DatabaseContextModelSnapshot.cs | 9 ++++ 18 files changed, 251 insertions(+), 109 deletions(-) delete mode 100644 util/MySqlMigrations/Migrations/20250207182213_AddOptionalNotifificationTaskId.cs rename util/MySqlMigrations/Migrations/{20250207182213_AddOptionalNotifificationTaskId.Designer.cs => 20250207204741_AddOptionalNotificationTaskId.Designer.cs} (99%) create mode 100644 util/MySqlMigrations/Migrations/20250207204741_AddOptionalNotificationTaskId.cs delete mode 100644 util/PostgresMigrations/Migrations/20250207182206_AddOptionalNotifificationTaskId.cs rename util/PostgresMigrations/Migrations/{20250207182206_AddOptionalNotifificationTaskId.Designer.cs => 20250207204729_AddOptionalNotificationTaskId.Designer.cs} (99%) create mode 100644 util/PostgresMigrations/Migrations/20250207204729_AddOptionalNotificationTaskId.cs delete mode 100644 util/SqliteMigrations/Migrations/20250207182157_AddOptionalNotifificationTaskId.cs rename util/SqliteMigrations/Migrations/{20250207182157_AddOptionalNotifificationTaskId.Designer.cs => 20250207204735_AddOptionalNotificationTaskId.Designer.cs} (99%) create mode 100644 util/SqliteMigrations/Migrations/20250207204735_AddOptionalNotificationTaskId.cs diff --git a/src/Infrastructure.EntityFramework/NotificationCenter/Configurations/NotificationEntityTypeConfiguration.cs b/src/Infrastructure.EntityFramework/NotificationCenter/Configurations/NotificationEntityTypeConfiguration.cs index c8bb2fd0ad7e..fc2bcd81c985 100644 --- a/src/Infrastructure.EntityFramework/NotificationCenter/Configurations/NotificationEntityTypeConfiguration.cs +++ b/src/Infrastructure.EntityFramework/NotificationCenter/Configurations/NotificationEntityTypeConfiguration.cs @@ -30,6 +30,10 @@ public void Configure(EntityTypeBuilder builder) .HasIndex(n => n.UserId) .IsClustered(false); + builder + .HasIndex(n => n.TaskId) + .IsClustered(false); + builder.ToTable(nameof(Notification)); } } diff --git a/src/Infrastructure.EntityFramework/NotificationCenter/Models/Notification.cs b/src/Infrastructure.EntityFramework/NotificationCenter/Models/Notification.cs index a13e99a2766b..ec8db45c5acc 100644 --- a/src/Infrastructure.EntityFramework/NotificationCenter/Models/Notification.cs +++ b/src/Infrastructure.EntityFramework/NotificationCenter/Models/Notification.cs @@ -1,6 +1,7 @@ using AutoMapper; using Bit.Infrastructure.EntityFramework.AdminConsole.Models; using Bit.Infrastructure.EntityFramework.Models; +using Bit.Infrastructure.EntityFramework.Vault.Models; namespace Bit.Infrastructure.EntityFramework.NotificationCenter.Models; @@ -8,6 +9,7 @@ public class Notification : Core.NotificationCenter.Entities.Notification { public virtual User User { get; set; } public virtual Organization Organization { get; set; } + public virtual SecurityTask Task { get; set; } } public class NotificationMapperProfile : Profile diff --git a/src/Sql/NotificationCenter/dbo/Stored Procedures/Notification_Create.sql b/src/Sql/NotificationCenter/dbo/Stored Procedures/Notification_Create.sql index 9924e26b98ac..7f6782305521 100644 --- a/src/Sql/NotificationCenter/dbo/Stored Procedures/Notification_Create.sql +++ b/src/Sql/NotificationCenter/dbo/Stored Procedures/Notification_Create.sql @@ -7,9 +7,9 @@ CREATE PROCEDURE [dbo].[Notification_Create] @OrganizationId UNIQUEIDENTIFIER, @Title NVARCHAR(256), @Body NVARCHAR(MAX), - @TaskId UNIQUEIDENTIFIER = NULL, @CreationDate DATETIME2(7), - @RevisionDate DATETIME2(7) + @RevisionDate DATETIME2(7), + @TaskId UNIQUEIDENTIFIER = NULL AS BEGIN SET NOCOUNT ON @@ -23,9 +23,9 @@ BEGIN [OrganizationId], [Title], [Body], - [TaskId], [CreationDate], - [RevisionDate] + [RevisionDate], + [TaskId] ) VALUES ( @Id, @@ -36,8 +36,8 @@ BEGIN @OrganizationId, @Title, @Body, - @TaskId, @CreationDate, - @RevisionDate + @RevisionDate, + @TaskId ) END diff --git a/src/Sql/NotificationCenter/dbo/Stored Procedures/Notification_Update.sql b/src/Sql/NotificationCenter/dbo/Stored Procedures/Notification_Update.sql index bcb80388be9d..4369c01f7118 100644 --- a/src/Sql/NotificationCenter/dbo/Stored Procedures/Notification_Update.sql +++ b/src/Sql/NotificationCenter/dbo/Stored Procedures/Notification_Update.sql @@ -7,9 +7,9 @@ CREATE PROCEDURE [dbo].[Notification_Update] @OrganizationId UNIQUEIDENTIFIER, @Title NVARCHAR(256), @Body NVARCHAR(MAX), - @TaskId UNIQUEIDENTIFIER = NULL, @CreationDate DATETIME2(7), - @RevisionDate DATETIME2(7) + @RevisionDate DATETIME2(7), + @TaskId UNIQUEIDENTIFIER = NULL AS BEGIN SET NOCOUNT ON @@ -22,8 +22,8 @@ BEGIN [OrganizationId] = @OrganizationId, [Title] = @Title, [Body] = @Body, - [TaskId] = @TaskId, [CreationDate] = @CreationDate, - [RevisionDate] = @RevisionDate + [RevisionDate] = @RevisionDate, + [TaskId] = @TaskId WHERE [Id] = @Id END diff --git a/src/Sql/NotificationCenter/dbo/Tables/Notification.sql b/src/Sql/NotificationCenter/dbo/Tables/Notification.sql index 3e54ce88b8ce..009985c5d016 100644 --- a/src/Sql/NotificationCenter/dbo/Tables/Notification.sql +++ b/src/Sql/NotificationCenter/dbo/Tables/Notification.sql @@ -8,12 +8,13 @@ CREATE TABLE [dbo].[Notification] [OrganizationId] UNIQUEIDENTIFIER NULL, [Title] NVARCHAR (256) NULL, [Body] NVARCHAR (MAX) NULL, - [TaskId] UNIQUEIDENTIFIER NULL, [CreationDate] DATETIME2 (7) NOT NULL, [RevisionDate] DATETIME2 (7) NOT NULL, + [TaskId] UNIQUEIDENTIFIER 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]) + CONSTRAINT [FK_Notification_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id]), + CONSTRAINT [FK_Notification_SecurityTask] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[SecurityTask] ([Id]) ); @@ -31,3 +32,6 @@ GO CREATE NONCLUSTERED INDEX [IX_Notification_OrganizationId] ON [dbo].[Notification]([OrganizationId] ASC) WHERE OrganizationId IS NOT NULL; +GO +CREATE NONCLUSTERED INDEX [IX_Notification_TaskId] + ON [dbo].[Notification] ([TaskId] ASC) WHERE TaskId IS NOT NULL; diff --git a/util/Migrator/DbScripts/2025-02-07_00_AddOptionalNotificationTaskId.sql b/util/Migrator/DbScripts/2025-02-07_00_AddOptionalNotificationTaskId.sql index 5345b49b7831..0e19cb5fe28c 100644 --- a/util/Migrator/DbScripts/2025-02-07_00_AddOptionalNotificationTaskId.sql +++ b/util/Migrator/DbScripts/2025-02-07_00_AddOptionalNotificationTaskId.sql @@ -1,12 +1,24 @@ --- Add optional Type column to Notification table +-- 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 --- Alter Notification_Create and Notification_Update stored procedures to include Type +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, @@ -16,9 +28,9 @@ CREATE OR ALTER PROCEDURE [dbo].[Notification_Create] @OrganizationId UNIQUEIDENTIFIER, @Title NVARCHAR(256), @Body NVARCHAR(MAX), - @TaskId UNIQUEIDENTIFIER = NULL, @CreationDate DATETIME2(7), - @RevisionDate DATETIME2(7) + @RevisionDate DATETIME2(7), + @TaskId UNIQUEIDENTIFIER = NULL AS BEGIN SET NOCOUNT ON @@ -32,9 +44,9 @@ BEGIN [OrganizationId], [Title], [Body], - [TaskId], [CreationDate], - [RevisionDate] + [RevisionDate], + [TaskId] ) VALUES ( @Id, @@ -45,9 +57,9 @@ BEGIN @OrganizationId, @Title, @Body, - @TaskId, @CreationDate, - @RevisionDate + @RevisionDate, + @TaskId ) END GO @@ -61,9 +73,9 @@ CREATE OR ALTER PROCEDURE [dbo].[Notification_Update] @OrganizationId UNIQUEIDENTIFIER, @Title NVARCHAR(256), @Body NVARCHAR(MAX), - @TaskId UNIQUEIDENTIFIER = NULL, @CreationDate DATETIME2(7), - @RevisionDate DATETIME2(7) + @RevisionDate DATETIME2(7), + @TaskId UNIQUEIDENTIFIER = NULL AS BEGIN SET NOCOUNT ON @@ -76,9 +88,9 @@ BEGIN [OrganizationId] = @OrganizationId, [Title] = @Title, [Body] = @Body, - [TaskId] = @TaskId, [CreationDate] = @CreationDate, - [RevisionDate] = @RevisionDate + [RevisionDate] = @RevisionDate, + [TaskId] = @TaskId WHERE [Id] = @Id END GO diff --git a/util/MySqlMigrations/Migrations/20250207182213_AddOptionalNotifificationTaskId.cs b/util/MySqlMigrations/Migrations/20250207182213_AddOptionalNotifificationTaskId.cs deleted file mode 100644 index 78f65e06597d..000000000000 --- a/util/MySqlMigrations/Migrations/20250207182213_AddOptionalNotifificationTaskId.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Bit.MySqlMigrations.Migrations; - -/// -public partial class AddOptionalNotifificationTaskId : Migration -{ - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "TaskId", - table: "Notification", - type: "char(36)", - nullable: true, - collation: "ascii_general_ci"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "TaskId", - table: "Notification"); - } -} diff --git a/util/MySqlMigrations/Migrations/20250207182213_AddOptionalNotifificationTaskId.Designer.cs b/util/MySqlMigrations/Migrations/20250207204741_AddOptionalNotificationTaskId.Designer.cs similarity index 99% rename from util/MySqlMigrations/Migrations/20250207182213_AddOptionalNotifificationTaskId.Designer.cs rename to util/MySqlMigrations/Migrations/20250207204741_AddOptionalNotificationTaskId.Designer.cs index ce073576c5b0..886f35f6d14c 100644 --- a/util/MySqlMigrations/Migrations/20250207182213_AddOptionalNotifificationTaskId.Designer.cs +++ b/util/MySqlMigrations/Migrations/20250207204741_AddOptionalNotificationTaskId.Designer.cs @@ -12,7 +12,7 @@ namespace Bit.MySqlMigrations.Migrations { [DbContext(typeof(DatabaseContext))] - [Migration("20250207182213_AddOptionalNotifificationTaskId")] + [Migration("20250207204741_AddOptionalNotifificationTaskId")] partial class AddOptionalNotifificationTaskId { /// @@ -1693,6 +1693,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("OrganizationId") .HasAnnotation("SqlServer:Clustered", false); + b.HasIndex("TaskId") + .HasAnnotation("SqlServer:Clustered", false); + b.HasIndex("UserId") .HasAnnotation("SqlServer:Clustered", false); @@ -2634,12 +2637,18 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .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"); }); diff --git a/util/MySqlMigrations/Migrations/20250207204741_AddOptionalNotificationTaskId.cs b/util/MySqlMigrations/Migrations/20250207204741_AddOptionalNotificationTaskId.cs new file mode 100644 index 000000000000..8881687b2a3c --- /dev/null +++ b/util/MySqlMigrations/Migrations/20250207204741_AddOptionalNotificationTaskId.cs @@ -0,0 +1,50 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Bit.MySqlMigrations.Migrations +{ + /// + public partial class AddOptionalNotifificationTaskId : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + 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"); + } + + /// + 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"); + } + } +} diff --git a/util/MySqlMigrations/Migrations/DatabaseContextModelSnapshot.cs b/util/MySqlMigrations/Migrations/DatabaseContextModelSnapshot.cs index b5d2f37f79e7..44ef9e01c34e 100644 --- a/util/MySqlMigrations/Migrations/DatabaseContextModelSnapshot.cs +++ b/util/MySqlMigrations/Migrations/DatabaseContextModelSnapshot.cs @@ -1690,6 +1690,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("OrganizationId") .HasAnnotation("SqlServer:Clustered", false); + b.HasIndex("TaskId") + .HasAnnotation("SqlServer:Clustered", false); + b.HasIndex("UserId") .HasAnnotation("SqlServer:Clustered", false); @@ -2631,12 +2634,18 @@ protected override void BuildModel(ModelBuilder modelBuilder) .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"); }); diff --git a/util/PostgresMigrations/Migrations/20250207182206_AddOptionalNotifificationTaskId.cs b/util/PostgresMigrations/Migrations/20250207182206_AddOptionalNotifificationTaskId.cs deleted file mode 100644 index 9b30eeb237d3..000000000000 --- a/util/PostgresMigrations/Migrations/20250207182206_AddOptionalNotifificationTaskId.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Bit.PostgresMigrations.Migrations; - -/// -public partial class AddOptionalNotifificationTaskId : Migration -{ - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "TaskId", - table: "Notification", - type: "uuid", - nullable: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "TaskId", - table: "Notification"); - } -} diff --git a/util/PostgresMigrations/Migrations/20250207182206_AddOptionalNotifificationTaskId.Designer.cs b/util/PostgresMigrations/Migrations/20250207204729_AddOptionalNotificationTaskId.Designer.cs similarity index 99% rename from util/PostgresMigrations/Migrations/20250207182206_AddOptionalNotifificationTaskId.Designer.cs rename to util/PostgresMigrations/Migrations/20250207204729_AddOptionalNotificationTaskId.Designer.cs index c6ae53c79349..57da6883fa6c 100644 --- a/util/PostgresMigrations/Migrations/20250207182206_AddOptionalNotifificationTaskId.Designer.cs +++ b/util/PostgresMigrations/Migrations/20250207204729_AddOptionalNotificationTaskId.Designer.cs @@ -12,7 +12,7 @@ namespace Bit.PostgresMigrations.Migrations { [DbContext(typeof(DatabaseContext))] - [Migration("20250207182206_AddOptionalNotifificationTaskId")] + [Migration("20250207204729_AddOptionalNotifificationTaskId")] partial class AddOptionalNotifificationTaskId { /// @@ -1699,6 +1699,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("OrganizationId") .HasAnnotation("SqlServer:Clustered", false); + b.HasIndex("TaskId") + .HasAnnotation("SqlServer:Clustered", false); + b.HasIndex("UserId") .HasAnnotation("SqlServer:Clustered", false); @@ -2640,12 +2643,18 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .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"); }); diff --git a/util/PostgresMigrations/Migrations/20250207204729_AddOptionalNotificationTaskId.cs b/util/PostgresMigrations/Migrations/20250207204729_AddOptionalNotificationTaskId.cs new file mode 100644 index 000000000000..2158bf7efeab --- /dev/null +++ b/util/PostgresMigrations/Migrations/20250207204729_AddOptionalNotificationTaskId.cs @@ -0,0 +1,49 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Bit.PostgresMigrations.Migrations +{ + /// + public partial class AddOptionalNotifificationTaskId : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + 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"); + } + + /// + 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"); + } + } +} diff --git a/util/PostgresMigrations/Migrations/DatabaseContextModelSnapshot.cs b/util/PostgresMigrations/Migrations/DatabaseContextModelSnapshot.cs index 621d86fba9bf..11fa811d9830 100644 --- a/util/PostgresMigrations/Migrations/DatabaseContextModelSnapshot.cs +++ b/util/PostgresMigrations/Migrations/DatabaseContextModelSnapshot.cs @@ -1696,6 +1696,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("OrganizationId") .HasAnnotation("SqlServer:Clustered", false); + b.HasIndex("TaskId") + .HasAnnotation("SqlServer:Clustered", false); + b.HasIndex("UserId") .HasAnnotation("SqlServer:Clustered", false); @@ -2637,12 +2640,18 @@ protected override void BuildModel(ModelBuilder modelBuilder) .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"); }); diff --git a/util/SqliteMigrations/Migrations/20250207182157_AddOptionalNotifificationTaskId.cs b/util/SqliteMigrations/Migrations/20250207182157_AddOptionalNotifificationTaskId.cs deleted file mode 100644 index f1ed10d0a029..000000000000 --- a/util/SqliteMigrations/Migrations/20250207182157_AddOptionalNotifificationTaskId.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Bit.SqliteMigrations.Migrations; - -/// -public partial class AddOptionalNotifificationTaskId : Migration -{ - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "TaskId", - table: "Notification", - type: "TEXT", - nullable: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "TaskId", - table: "Notification"); - } -} diff --git a/util/SqliteMigrations/Migrations/20250207182157_AddOptionalNotifificationTaskId.Designer.cs b/util/SqliteMigrations/Migrations/20250207204735_AddOptionalNotificationTaskId.Designer.cs similarity index 99% rename from util/SqliteMigrations/Migrations/20250207182157_AddOptionalNotifificationTaskId.Designer.cs rename to util/SqliteMigrations/Migrations/20250207204735_AddOptionalNotificationTaskId.Designer.cs index f24a37cd760f..98d0871ec10c 100644 --- a/util/SqliteMigrations/Migrations/20250207182157_AddOptionalNotifificationTaskId.Designer.cs +++ b/util/SqliteMigrations/Migrations/20250207204735_AddOptionalNotificationTaskId.Designer.cs @@ -11,7 +11,7 @@ namespace Bit.SqliteMigrations.Migrations { [DbContext(typeof(DatabaseContext))] - [Migration("20250207182157_AddOptionalNotifificationTaskId")] + [Migration("20250207204735_AddOptionalNotifificationTaskId")] partial class AddOptionalNotifificationTaskId { /// @@ -1682,6 +1682,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("OrganizationId") .HasAnnotation("SqlServer:Clustered", false); + b.HasIndex("TaskId") + .HasAnnotation("SqlServer:Clustered", false); + b.HasIndex("UserId") .HasAnnotation("SqlServer:Clustered", false); @@ -2623,12 +2626,18 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .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"); }); diff --git a/util/SqliteMigrations/Migrations/20250207204735_AddOptionalNotificationTaskId.cs b/util/SqliteMigrations/Migrations/20250207204735_AddOptionalNotificationTaskId.cs new file mode 100644 index 000000000000..d2279ed3dfbe --- /dev/null +++ b/util/SqliteMigrations/Migrations/20250207204735_AddOptionalNotificationTaskId.cs @@ -0,0 +1,49 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Bit.SqliteMigrations.Migrations +{ + /// + public partial class AddOptionalNotifificationTaskId : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + 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"); + } + + /// + 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"); + } + } +} diff --git a/util/SqliteMigrations/Migrations/DatabaseContextModelSnapshot.cs b/util/SqliteMigrations/Migrations/DatabaseContextModelSnapshot.cs index 4bc89428dd2a..8d122f561756 100644 --- a/util/SqliteMigrations/Migrations/DatabaseContextModelSnapshot.cs +++ b/util/SqliteMigrations/Migrations/DatabaseContextModelSnapshot.cs @@ -1679,6 +1679,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("OrganizationId") .HasAnnotation("SqlServer:Clustered", false); + b.HasIndex("TaskId") + .HasAnnotation("SqlServer:Clustered", false); + b.HasIndex("UserId") .HasAnnotation("SqlServer:Clustered", false); @@ -2620,12 +2623,18 @@ protected override void BuildModel(ModelBuilder modelBuilder) .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"); });