WIP: Record history
This commit is contained in:
@@ -8,6 +8,7 @@ public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(op
|
||||
public DbSet<User> Users { get; init; }
|
||||
public DbSet<Layer> Layers { get; init; }
|
||||
public DbSet<Record> Records { get; init; }
|
||||
public DbSet<RecordHistory> RecordHistory { get; init; }
|
||||
public DbSet<ProcessSource> ProcessSources { get; init; }
|
||||
public DbSet<DataInbox> DataInbox { get; init; }
|
||||
public DbSet<QueueJob> QueueJobs { get; init; }
|
||||
@@ -75,6 +76,30 @@ public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(op
|
||||
.HasForeignKey(x => x.LayerId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<RecordHistory>().HasKey(x => x.Id);
|
||||
modelBuilder.Entity<RecordHistory>().Property(x => x.RecordId).IsRequired();
|
||||
modelBuilder.Entity<RecordHistory>().Property(x => x.LayerId).IsRequired();
|
||||
modelBuilder.Entity<RecordHistory>().Property(x => x.ChangedAt).IsRequired();
|
||||
modelBuilder.Entity<RecordHistory>().Property(x => x.ChangedById).IsRequired();
|
||||
modelBuilder.Entity<RecordHistory>().Property(x => x.ChangeType).IsRequired().HasConversion<int>();
|
||||
modelBuilder.Entity<RecordHistory>().Property(x => x.Code).IsRequired().HasMaxLength(50);
|
||||
modelBuilder.Entity<RecordHistory>().Property(x => x.Desc1).HasMaxLength(10000);
|
||||
modelBuilder.Entity<RecordHistory>().Property(x => x.ChangedFields).HasMaxLength(200);
|
||||
modelBuilder.Entity<RecordHistory>().Property(x => x.ChangesSummary).HasMaxLength(4000);
|
||||
|
||||
// Indexes for efficient history queries
|
||||
modelBuilder.Entity<RecordHistory>()
|
||||
.HasIndex(x => new { x.RecordId, x.ChangedAt });
|
||||
|
||||
modelBuilder.Entity<RecordHistory>()
|
||||
.HasIndex(x => new { x.LayerId, x.ChangedAt });
|
||||
|
||||
modelBuilder.Entity<RecordHistory>()
|
||||
.HasOne(x => x.ChangedBy)
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ChangedById)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
modelBuilder.Entity<ProcessSource>().HasKey(x => new { x.LayerId, x.SourceId });
|
||||
modelBuilder.Entity<ProcessSource>().Property(x => x.LayerId).IsRequired();
|
||||
modelBuilder.Entity<ProcessSource>().Property(x => x.SourceId).IsRequired();
|
||||
|
||||
Reference in New Issue
Block a user