feat(ai): centralize durable usage
CI and Deploy / test (pull_request) Successful in 5m19s
CI and Deploy / deploy (pull_request) Has been skipped

Add a content-free usage ledger with legacy backfill. Reserve Workspace and durable Strategy/CV work before execution so deleted history or duplicate admission cannot reset limits.
This commit is contained in:
cesnimda
2026-08-15 20:03:06 +02:00
parent dbff0f8d49
commit 134aac7bcf
28 changed files with 3539 additions and 83 deletions
+13
View File
@@ -56,6 +56,7 @@ namespace JobTrackerApi.Data
public DbSet<CvVariant> CvVariants => Set<CvVariant>();
public DbSet<CvVariantVersion> CvVariantVersions => Set<CvVariantVersion>();
public DbSet<AiInteraction> AiInteractions => Set<AiInteraction>();
public DbSet<AiUsageRecord> AiUsageRecords => Set<AiUsageRecord>();
public DbSet<ApplicationChecklistItem> ApplicationChecklistItems => Set<ApplicationChecklistItem>();
public DbSet<CoverLetterVersion> CoverLetterVersions => Set<CoverLetterVersion>();
public DbSet<InterviewPrepItem> InterviewPrepItems => Set<InterviewPrepItem>();
@@ -482,6 +483,18 @@ namespace JobTrackerApi.Data
.HasForeignKey(x => x.JobApplicationId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<AiUsageRecord>()
.HasQueryFilter(x => CurrentUserId != null && x.OwnerUserId == CurrentUserId);
modelBuilder.Entity<AiUsageRecord>().Property(x => x.OwnerUserId).HasMaxLength(255);
modelBuilder.Entity<AiUsageRecord>().Property(x => x.SourceType).HasMaxLength(32);
modelBuilder.Entity<AiUsageRecord>().Property(x => x.SourceId).HasMaxLength(64);
modelBuilder.Entity<AiUsageRecord>().Property(x => x.TaskType).HasMaxLength(64);
modelBuilder.Entity<AiUsageRecord>()
.HasIndex(x => new { x.OwnerUserId, x.SourceType, x.SourceId })
.IsUnique();
modelBuilder.Entity<AiUsageRecord>()
.HasIndex(x => new { x.OwnerUserId, x.CreatedAtUtc });
// Phase 5 Milestone 2: the application checklist — a workflow guidance layer over the existing
// readiness signals, not a second store of truth. Same deny-on-null tenant filter; cascades with
// the application. docs/architecture/application-workspace.md.