diff --git a/BTCPayServer.Data/Data/NotificationData.cs b/BTCPayServer.Data/Data/NotificationData.cs index e1a655ca5..a54afb521 100644 --- a/BTCPayServer.Data/Data/NotificationData.cs +++ b/BTCPayServer.Data/Data/NotificationData.cs @@ -26,7 +26,7 @@ namespace BTCPayServer.Data builder.Entity() .HasOne(o => o.ApplicationUser) .WithMany(n => n.Notifications) - .HasForeignKey(k => k.ApplicationUserId); + .HasForeignKey(k => k.ApplicationUserId).OnDelete(DeleteBehavior.Cascade); } } } diff --git a/BTCPayServer.Data/Migrations/20200613234439_CascadeDeleteNotificationsForUser.cs b/BTCPayServer.Data/Migrations/20200613234439_CascadeDeleteNotificationsForUser.cs new file mode 100644 index 000000000..882770f55 --- /dev/null +++ b/BTCPayServer.Data/Migrations/20200613234439_CascadeDeleteNotificationsForUser.cs @@ -0,0 +1,41 @@ +using BTCPayServer.Data; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace BTCPayServer.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20200613234439_CascadeDeleteNotificationsForUser")] + public partial class CascadeDeleteNotificationsForUser : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Notifications_AspNetUsers_ApplicationUserId", + table: "Notifications"); + + migrationBuilder.AddForeignKey( + name: "FK_Notifications_AspNetUsers_ApplicationUserId", + table: "Notifications", + column: "ApplicationUserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Notifications_AspNetUsers_ApplicationUserId", + table: "Notifications"); + + migrationBuilder.AddForeignKey( + name: "FK_Notifications_AspNetUsers_ApplicationUserId", + table: "Notifications", + column: "ApplicationUserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + } +} diff --git a/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs b/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs index 5ae1b5f03..3bc9b6310 100644 --- a/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -794,7 +794,8 @@ namespace BTCPayServer.Migrations { b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") .WithMany("Notifications") - .HasForeignKey("ApplicationUserId"); + .HasForeignKey("ApplicationUserId") + .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity("BTCPayServer.Data.PairedSINData", b =>