using backend.Auth; using backend.Devices; using backend.Settings; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace backend.Data; public class AppDbContext(DbContextOptions options) : IdentityDbContext, Guid>(options) { public DbSet Devices => Set(); public DbSet DeviceConfigs => Set(); public DbSet SystemSettings => Set(); protected override void OnModelCreating(ModelBuilder b) { base.OnModelCreating(b); b.Entity().HasIndex(d => d.OwnerUserId); b.Entity().HasIndex(d => d.TokenHash).IsUnique(); b.Entity() .HasOne(d => d.Config) .WithOne() .HasForeignKey(c => c.DeviceId) .OnDelete(DeleteBehavior.Cascade); b.Entity().HasKey(c => c.DeviceId); b.Entity().HasKey(s => s.Id); } }