Cascade delete notifications for user

This commit is contained in:
rockstardev
2020-06-13 18:45:44 -05:00
parent 455ac8786a
commit 09a72f2cfb
3 changed files with 44 additions and 2 deletions

View File

@@ -26,7 +26,7 @@ namespace BTCPayServer.Data
builder.Entity<NotificationData>() builder.Entity<NotificationData>()
.HasOne(o => o.ApplicationUser) .HasOne(o => o.ApplicationUser)
.WithMany(n => n.Notifications) .WithMany(n => n.Notifications)
.HasForeignKey(k => k.ApplicationUserId); .HasForeignKey(k => k.ApplicationUserId).OnDelete(DeleteBehavior.Cascade);
} }
} }
} }

View File

@@ -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);
}
}
}

View File

@@ -794,7 +794,8 @@ namespace BTCPayServer.Migrations
{ {
b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser")
.WithMany("Notifications") .WithMany("Notifications")
.HasForeignKey("ApplicationUserId"); .HasForeignKey("ApplicationUserId")
.OnDelete(DeleteBehavior.Cascade);
}); });
modelBuilder.Entity("BTCPayServer.Data.PairedSINData", b => modelBuilder.Entity("BTCPayServer.Data.PairedSINData", b =>