Refactored out hardcoded logpath and DB connection string and made them configurable through appsettings.json. Add persistent store path in docker-compose.
37 lines
No EOL
1.1 KiB
C#
37 lines
No EOL
1.1 KiB
C#
using System.Linq;
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using RdtClient.Data.Models.Data;
|
|
|
|
namespace RdtClient.Data.Data
|
|
{
|
|
public class DataContext : IdentityDbContext
|
|
{
|
|
public DataContext(DbContextOptions options) : base(options)
|
|
{
|
|
}
|
|
|
|
public DbSet<Download> Downloads { get; set; }
|
|
public DbSet<Setting> Settings { get; set; }
|
|
public DbSet<Torrent> Torrents { get; set; }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
|
{
|
|
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
{
|
|
base.OnModelCreating(builder);
|
|
|
|
var cascadeFKs = builder.Model.GetEntityTypes()
|
|
.SelectMany(t => t.GetForeignKeys())
|
|
.Where(fk => !fk.IsOwnership && fk.DeleteBehavior == DeleteBehavior.Cascade);
|
|
|
|
foreach (var fk in cascadeFKs)
|
|
{
|
|
fk.DeleteBehavior = DeleteBehavior.Restrict;
|
|
}
|
|
}
|
|
}
|
|
} |