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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user