fix(rd21): guard career and job saves with durable revisions

This commit is contained in:
cesnimda
2026-10-23 08:07:23 +02:00
parent 8f2cad67f7
commit 12f342c09c
32 changed files with 1185 additions and 277 deletions
+25
View File
@@ -72,10 +72,35 @@ namespace JobTrackerApi.Data
public DbSet<AccountDeletionRequest> AccountDeletionRequests => Set<AccountDeletionRequest>();
public DbSet<AccountDeletionFile> AccountDeletionFiles => Set<AccountDeletionFile>();
private void AdvanceJobRevisions()
{
ChangeTracker.DetectChanges();
foreach (var entry in ChangeTracker.Entries<JobApplication>().Where(x => x.State == EntityState.Modified))
{
// All writers share this guard, including partial updates and background workers.
entry.Entity.Version = checked(entry.Property(x => x.Version).OriginalValue + 1);
}
}
public override int SaveChanges(bool acceptAllChangesOnSuccess)
{
AdvanceJobRevisions();
return base.SaveChanges(acceptAllChangesOnSuccess);
}
public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
{
AdvanceJobRevisions();
return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<JobApplication>().Property(x => x.Version).IsConcurrencyToken().HasDefaultValue(1);
modelBuilder.Entity<CareerProfile>().Property(x => x.Version).IsConcurrencyToken();
modelBuilder.Entity<ApplicationUser>()
.Property(x => x.PendingEmail)
.HasMaxLength(320);