fix(cv): make initial revision atomic
CI and Deploy / test (push) Failing after 8m11s
CI and Deploy / deploy (push) Has been skipped

This commit is contained in:
cesnimda
2026-08-29 02:13:05 +02:00
parent 9cfe622103
commit a3b4941447
4 changed files with 42 additions and 10 deletions
@@ -81,6 +81,12 @@ public sealed class CvVariantService : ICvVariantService
{
if (jobApplicationId is not null && !await CanAssociateJobAsync(ownerUserId, jobApplicationId.Value, ct))
throw new ArgumentException("The job application is unavailable.", nameof(jobApplicationId));
// The first save is required to obtain the generated variant id used by its initial
// history row. Keep both saves in one relational transaction so a concurrent autosave
// cannot slip between them and leave a created CV without version 1.
await using var transaction = _db.Database.IsRelational()
? await _db.Database.BeginTransactionAsync(ct)
: null;
var now = DateTimeOffset.UtcNow;
var normalized = CvVariantSettingsJson.Normalize(settings);
var variant = new CvVariant
@@ -98,6 +104,7 @@ public sealed class CvVariantService : ICvVariantService
await _db.SaveChangesAsync(ct);
AppendVersion(variant, "create");
await _db.SaveChangesAsync(ct);
if (transaction is not null) await transaction.CommitAsync(ct);
return variant;
}