Add Device, DeviceConfig, SystemSettings entities and seed defaults

This commit is contained in:
2026-06-11 18:41:27 +00:00
parent a1aa5023a2
commit 68e7e81312
8 changed files with 634 additions and 1 deletions
+20
View File
@@ -1,4 +1,6 @@
using backend.Auth;
using backend.Devices;
using backend.Settings;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
@@ -8,4 +10,22 @@ namespace backend.Data;
public class AppDbContext(DbContextOptions<AppDbContext> options)
: IdentityDbContext<ApplicationUser, IdentityRole<Guid>, Guid>(options)
{
public DbSet<Device> Devices => Set<Device>();
public DbSet<DeviceConfig> DeviceConfigs => Set<DeviceConfig>();
public DbSet<SystemSettings> SystemSettings => Set<SystemSettings>();
protected override void OnModelCreating(ModelBuilder b)
{
base.OnModelCreating(b);
b.Entity<Device>().HasIndex(d => d.OwnerUserId);
b.Entity<Device>().HasIndex(d => d.TokenHash).IsUnique();
b.Entity<Device>()
.HasOne(d => d.Config)
.WithOne()
.HasForeignKey<DeviceConfig>(c => c.DeviceId)
.OnDelete(DeleteBehavior.Cascade);
b.Entity<DeviceConfig>().HasKey(c => c.DeviceId);
b.Entity<SystemSettings>().HasKey(s => s.Id);
}
}