Fix data purge FK violation on Appointments and apply pending migration

DataPurgeController was deleting Jobs without first clearing the nullable
Appointments.JobId FK, causing FK_Appointments_Jobs_JobId violations.
Fix nulls out the FK on any linked appointments before the DELETE runs.

Also applies migration AddAllowCustomFormulas (AllowCustomFormulas column
on SubscriptionPlanConfigs for custom formula pricing feature gating).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 08:54:48 -04:00
parent 91a176ce5c
commit 5b5247624c
4 changed files with 10871 additions and 3 deletions
@@ -293,6 +293,16 @@ public class DataPurgeController : Controller
break;
case "Jobs":
// Appointments.JobId is a nullable FK — null it out first so the DELETE
// doesn't violate FK_Appointments_Jobs_JobId.
var purgingJobIds = await _db.Jobs.IgnoreQueryFilters()
.Where(e => e.IsDeleted && e.DeletedAt <= cutoff)
.Select(e => e.Id)
.ToListAsync();
if (purgingJobIds.Count > 0)
await _db.Appointments.IgnoreQueryFilters()
.Where(a => a.JobId.HasValue && purgingJobIds.Contains(a.JobId.Value))
.ExecuteUpdateAsync(s => s.SetProperty(a => a.JobId, (int?)null));
count = await _db.Jobs.IgnoreQueryFilters()
.Where(e => e.IsDeleted && e.DeletedAt <= cutoff).ExecuteDeleteAsync();
break;