Add Device, DeviceConfig, SystemSettings entities and seed defaults
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user