Add Conversation + Turn entities and migration

This commit is contained in:
2026-06-11 21:09:52 +00:00
parent 58b8a446b1
commit 99cfe60a2c
6 changed files with 686 additions and 0 deletions
+11
View File
@@ -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();
}
}