Add Conversation + Turn entities and migration
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using backend.Auth;
|
||||
using backend.Conversations;
|
||||
using backend.Devices;
|
||||
using backend.Pairing;
|
||||
using backend.Settings;
|
||||
@@ -15,6 +16,8 @@ public class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
public DbSet<DeviceConfig> DeviceConfigs => Set<DeviceConfig>();
|
||||
public DbSet<SystemSettings> SystemSettings => Set<SystemSettings>();
|
||||
public DbSet<PairingCode> PairingCodes => Set<PairingCode>();
|
||||
public DbSet<Conversation> Conversations => Set<Conversation>();
|
||||
public DbSet<Turn> Turns => Set<Turn>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder b)
|
||||
{
|
||||
@@ -36,5 +39,13 @@ public class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
b.Entity<SystemSettings>().Property(s => s.Id).ValueGeneratedNever();
|
||||
b.Entity<PairingCode>().HasKey(p => p.Code);
|
||||
b.Entity<PairingCode>().HasIndex(p => p.ExpiresAt);
|
||||
|
||||
b.Entity<Conversation>().HasIndex(c => c.DeviceId);
|
||||
b.Entity<Conversation>()
|
||||
.HasMany(c => c.Turns)
|
||||
.WithOne()
|
||||
.HasForeignKey(t => t.ConversationId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
b.Entity<Turn>().HasIndex(t => new { t.ConversationId, t.Index }).IsUnique();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user