| | | 1 | | using Elsa.AI.Persistence.EFCore.Entities; |
| | | 2 | | |
| | | 3 | | namespace Elsa.AI.Persistence.EFCore; |
| | | 4 | | |
| | 38 | 5 | | public class AIDbContext(DbContextOptions<AIDbContext> options) : DbContext(options) |
| | | 6 | | { |
| | 58 | 7 | | public DbSet<AIConversationRecord> Conversations => Set<AIConversationRecord>(); |
| | 40 | 8 | | public DbSet<AIProposalRecord> Proposals => Set<AIProposalRecord>(); |
| | 10 | 9 | | public DbSet<AIAuditRecord> AuditRecords => Set<AIAuditRecord>(); |
| | | 10 | | |
| | | 11 | | protected override void OnModelCreating(ModelBuilder modelBuilder) |
| | | 12 | | { |
| | 2 | 13 | | modelBuilder.Entity<AIProposalRecord>(entity => |
| | 2 | 14 | | { |
| | 2 | 15 | | entity.ToTable("AIProposals"); |
| | 2 | 16 | | entity.HasKey(x => x.Id); |
| | 2 | 17 | | entity.HasIndex(x => new { x.TenantId, x.ConversationId }); |
| | 2 | 18 | | entity.HasIndex(x => x.Status); |
| | 2 | 19 | | entity.Property(x => x.WorkflowPayload).IsRequired(); |
| | 2 | 20 | | entity.Property(x => x.ValidationDiagnostics).IsRequired(); |
| | 2 | 21 | | entity.Property(x => x.Warnings).IsRequired(); |
| | 4 | 22 | | }); |
| | | 23 | | |
| | 2 | 24 | | modelBuilder.Entity<AIAuditRecord>(entity => |
| | 2 | 25 | | { |
| | 2 | 26 | | entity.ToTable("AIAuditRecords"); |
| | 2 | 27 | | entity.HasKey(x => x.Id); |
| | 2 | 28 | | entity.HasIndex(x => new { x.TenantId, x.ConversationId }); |
| | 2 | 29 | | entity.HasIndex(x => x.ActorId); |
| | 2 | 30 | | entity.HasIndex(x => new { x.TenantId, x.Timestamp }); |
| | 2 | 31 | | entity.HasIndex(x => x.ProposalId); |
| | 2 | 32 | | entity.HasIndex(x => x.ToolInvocationId); |
| | 2 | 33 | | entity.Property(x => x.Type).IsRequired(); |
| | 2 | 34 | | entity.Property(x => x.Data).IsRequired(); |
| | 4 | 35 | | }); |
| | | 36 | | |
| | 2 | 37 | | modelBuilder.Entity<AIConversationRecord>(entity => |
| | 2 | 38 | | { |
| | 2 | 39 | | entity.ToTable("AIConversations"); |
| | 2 | 40 | | entity.HasKey(x => x.Id); |
| | 2 | 41 | | entity.HasIndex(x => new { x.TenantId, x.UserId }); |
| | 2 | 42 | | entity.HasIndex(x => x.Status); |
| | 2 | 43 | | entity.HasIndex(x => x.RetentionExpiresAt); |
| | 2 | 44 | | entity.Property(x => x.UserId).IsRequired(); |
| | 2 | 45 | | entity.Property(x => x.Status).IsRequired(); |
| | 2 | 46 | | entity.Property(x => x.RetentionMode).IsRequired(); |
| | 2 | 47 | | entity.Property(x => x.Messages).IsRequired(); |
| | 4 | 48 | | }); |
| | 2 | 49 | | } |
| | | 50 | | } |