Make U2F devices cascade delete

fixes #1949
This commit is contained in:
Kukks 2020-10-06 17:56:55 +02:00
parent cfa568a230
commit 2147f8ec8b
2 changed files with 13 additions and 1 deletions

View File

@ -90,7 +90,8 @@ namespace BTCPayServer.Data
PullPaymentData.OnModelCreating(builder); PullPaymentData.OnModelCreating(builder);
PayoutData.OnModelCreating(builder); PayoutData.OnModelCreating(builder);
RefundData.OnModelCreating(builder); RefundData.OnModelCreating(builder);
U2FDevice.OnModelCreating(builder);
if (Database.IsSqlite() && !_designTime) if (Database.IsSqlite() && !_designTime)
{ {
// SQLite does not have proper support for DateTimeOffset via Entity Framework Core, see the limitations // SQLite does not have proper support for DateTimeOffset via Entity Framework Core, see the limitations

View File

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
namespace BTCPayServer.Data namespace BTCPayServer.Data
{ {
@ -18,5 +19,15 @@ namespace BTCPayServer.Data
public string ApplicationUserId { get; set; } public string ApplicationUserId { get; set; }
public ApplicationUser ApplicationUser { get; set; } public ApplicationUser ApplicationUser { get; set; }
internal static void OnModelCreating(ModelBuilder builder)
{
builder.Entity<U2FDevice>()
.HasOne(o => o.ApplicationUser)
.WithMany(i => i.U2FDevices)
.HasForeignKey(i => i.ApplicationUserId).OnDelete(DeleteBehavior.Cascade);
}
} }
} }