fix: recreate policy when removing WITH CHECK clause (#551) - #554
Conversation
PostgreSQL ALTER POLICY cannot clear an existing WITH CHECK expression, so removing it requires DROP + CREATE. Previously this emitted invalid SQL `WITH CHECK ;`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR changes removal of a policy WITH CHECK clause from an invalid ALTER POLICY operation to transactional DROP-and-CREATE recreation.
Confidence Score: 4/5The policy recreation behavior should preserve existing policy comments before this PR is merged. Removing WITH CHECK now drops and recreates the policy, but the recreation generator restores only structural clauses, so any existing COMMENT ON POLICY metadata is silently deleted. Files Needing Attention: internal/diff/policy.go and the policy recreation branch in internal/diff/table.go Important Files Changed
Reviews (1): Last reviewed commit: "fix: recreate policy when removing WITH ..." | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
Fixes invalid SQL generation when removing an explicit RLS policy WITH CHECK clause by forcing policy recreation (DROP + CREATE) instead of attempting ALTER POLICY, and adds a regression diff test case for the reported scenario (#551).
Changes:
- Update
needsRecreateto return true when a policy’sWITH CHECKclause is removed, avoiding invalidWITH CHECK ;output. - Add a new diff regression fixture
issue_551_remove_with_checkvalidating DROP + CREATE plan output.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
internal/diff/policy.go |
Changes policy recreation decision logic to handle WITH CHECK removal correctly. |
testdata/diff/create_policy/issue_551_remove_with_check/* |
Adds regression fixture asserting DROP + CREATE behavior in plan/diff outputs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Address review feedback: - USING removal has the same invalid SQL problem as WITH CHECK removal; add it to needsRecreate so it also triggers DROP + CREATE. - Emit COMMENT ON POLICY after recreation to preserve existing comments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
WITH CHECKclause is removed,needsRecreatenow returns true, triggering DROP + CREATE instead of ALTER POLICYWITH CHECK ;because ALTER POLICY cannot clear an existing WITH CHECK expressionissue_551_remove_with_checkverifying DROP + CREATE outputCloses #551
Test plan
🤖 Generated with Claude Code