Skip to content

fix(policies): preserve entityId when re-generating a policy#2382

Merged
Marfuen merged 3 commits intomainfrom
eng-90-fix-policy-entityid-null
Apr 2, 2026
Merged

fix(policies): preserve entityId when re-generating a policy#2382
Marfuen merged 3 commits intomainfrom
eng-90-fix-policy-entityid-null

Conversation

@tofikwest
Copy link
Copy Markdown
Contributor

Summary

  • Fixes bug where currentVersionId became null during policy regeneration
  • Root cause: deleting policy versions triggered FK cascade (SET NULL) on the policy's currentVersionId before the new version was written
  • Fix: explicitly clear currentVersionId and pendingVersionId before deleteMany within the transaction
  • Applied to both API-side and app-side (bulk regeneration) copies of updatePolicyInDatabase

Test plan

  • Regenerate a single policy — verify it saves correctly with a valid currentVersionId
  • Regenerate all policies via onboarding flow — verify none end up with null currentVersionId
  • Verify policy content displays correctly after regeneration

Resolves ENG-90

🤖 Generated with Claude Code

Resolves ENG-90

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@linear
Copy link
Copy Markdown

linear bot commented Mar 30, 2026

@cursor
Copy link
Copy Markdown

cursor bot commented Mar 30, 2026

PR Summary

Medium Risk
Touches version deletion and currentVersionId/pendingVersionId updates inside a DB transaction; mistakes here could leave policies without a valid current version. Scope is small and duplicated in two helper implementations (API and onboarding).

Overview
Fixes policy regeneration to avoid foreign-key constraint/cascade side effects when removing old policy versions.

In both the API and onboarding updatePolicyInDatabase helpers, the transaction now explicitly nulls currentVersionId and pendingVersionId on the policy record before deleteMany removes existing policyVersion rows, then creates a fresh version and reassigns currentVersionId.

Written by Cursor Bugbot for commit 71f0637. This will update automatically on new commits. Configure here.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
app Ready Ready Preview, Comment Apr 2, 2026 8:03pm
comp-framework-editor Ready Ready Preview, Comment Apr 2, 2026 8:03pm
portal Ready Ready Preview, Comment Apr 2, 2026 8:03pm

Request Review

@Marfuen Marfuen merged commit 0324329 into main Apr 2, 2026
10 checks passed
@Marfuen Marfuen deleted the eng-90-fix-policy-entityid-null branch April 2, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants