Phase 1-4: Add soft delete, concurrency token, update EF config and controllers
- Add ISoftDeletable interface with IsDeleted/DeletedAt - Implement on Budget, Income, Outgo, BudgetShare; add RowVersion (xmin) to Budget - Configure EF global query filters and xmin concurrency token - Replace Remove() with soft delete in all delete endpoints - Wrap Budget.Update SaveChanges in DbUpdateConcurrencyException catch
This commit is contained in:
@@ -22,6 +22,12 @@ public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(op
|
||||
b.HasMany(x => x.Incomes).WithOne(i => i.Budget).HasForeignKey(i => i.BudgetId).OnDelete(DeleteBehavior.Cascade);
|
||||
b.HasMany(x => x.Outgos).WithOne(o => o.Budget).HasForeignKey(o => o.BudgetId).OnDelete(DeleteBehavior.Cascade);
|
||||
b.HasMany(x => x.Shares).WithOne(s => s.Budget).HasForeignKey(s => s.BudgetId).OnDelete(DeleteBehavior.Cascade);
|
||||
b.HasQueryFilter(x => !x.IsDeleted);
|
||||
b.Property(e => e.RowVersion)
|
||||
.HasColumnName("xmin")
|
||||
.HasColumnType("xid")
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.IsConcurrencyToken();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Income>(b =>
|
||||
@@ -29,6 +35,7 @@ public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(op
|
||||
b.HasKey(x => x.Id);
|
||||
b.Property(x => x.Name).IsRequired().HasMaxLength(200);
|
||||
b.Property(x => x.Amount).HasPrecision(18, 2);
|
||||
b.HasQueryFilter(x => !x.IsDeleted);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Outgo>(b =>
|
||||
@@ -39,6 +46,7 @@ public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(op
|
||||
b.Property(x => x.PaymentSource).HasMaxLength(100);
|
||||
b.Property(x => x.Notes).HasMaxLength(1000);
|
||||
b.Property(x => x.Amount).HasPrecision(18, 2);
|
||||
b.HasQueryFilter(x => !x.IsDeleted);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<KnownUser>(b =>
|
||||
@@ -55,6 +63,7 @@ public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(op
|
||||
b.Property(x => x.SharedWithUserId).HasMaxLength(200);
|
||||
b.Property(x => x.SharedWithEmail).IsRequired().HasMaxLength(200);
|
||||
b.HasIndex(x => new { x.BudgetId, x.SharedWithEmail }).IsUnique();
|
||||
b.HasQueryFilter(x => !x.IsDeleted);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user