Skip to content

Conversation

@tianzhou
Copy link
Contributor

Fix #203

Policy names were not being quoted in CREATE POLICY, ALTER POLICY, and DROP POLICY statements, causing SQL errors for policies with:

  • Reserved words as names (e.g., "select")
  • Mixed case names (e.g., "UserPolicy")
  • Special characters (e.g., "my-policy")

Added ir.QuoteIdentifier() calls in:

  • internal/diff/policy.go: CREATE POLICY and ALTER POLICY
  • internal/diff/table.go: DROP POLICY statements

Enhanced add_policy test case to cover all quoting scenarios.

🤖 Generated with Claude Code

Policy names were not being quoted in CREATE POLICY, ALTER POLICY, and
DROP POLICY statements, causing SQL errors for policies with:
- Reserved words as names (e.g., "select")
- Mixed case names (e.g., "UserPolicy")
- Special characters (e.g., "my-policy")

Added ir.QuoteIdentifier() calls in:
- internal/diff/policy.go: CREATE POLICY and ALTER POLICY
- internal/diff/table.go: DROP POLICY statements

Enhanced add_policy test case to cover all quoting scenarios.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings December 18, 2025 05:47
@tianzhou tianzhou changed the title fix: quote policy names in DDL output (#203) fix: quote policy names in DDL output Dec 18, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #203 by adding proper identifier quoting for policy names in all DDL output statements. Policy names containing reserved words (e.g., "select"), mixed case (e.g., "UserPolicy"), or special characters (e.g., "my-policy") now generate valid SQL with quoted identifiers.

Key Changes:

  • Added ir.QuoteIdentifier() calls for policy names in CREATE POLICY, ALTER POLICY, and DROP POLICY statements
  • Enhanced test coverage with comprehensive examples covering reserved words, mixed case, special characters, and regular snake_case names

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/diff/policy.go Added quoting to CREATE POLICY (line 65) and ALTER POLICY (line 107) statements
internal/diff/table.go Added quoting to DROP POLICY statements for both dropped policies (line 918) and policies requiring recreation (line 1009)
testdata/diff/create_policy/add_policy/new.sql Enhanced test case with four policies demonstrating different quoting scenarios
testdata/diff/create_policy/add_policy/old.sql Added role column to support new test policies
testdata/diff/create_policy/add_policy/plan.txt Updated expected output showing properly quoted policy names
testdata/diff/create_policy/add_policy/plan.sql Updated expected DDL with quoted identifiers
testdata/diff/create_policy/add_policy/plan.json Updated JSON plan with all four test policies and proper quoting
testdata/diff/create_policy/add_policy/diff.sql Updated diff output showing all four policy creations with proper quoting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tianzhou tianzhou merged commit da806cd into main Dec 18, 2025
8 checks passed
@tianzhou tianzhou deleted the policy_quote branch December 18, 2025 07:24
alecthomas pushed a commit to alecthomas/pgschema that referenced this pull request Jan 26, 2026
Policy names were not being quoted in CREATE POLICY, ALTER POLICY, and
DROP POLICY statements, causing SQL errors for policies with:
- Reserved words as names (e.g., "select")
- Mixed case names (e.g., "UserPolicy")
- Special characters (e.g., "my-policy")

Added ir.QuoteIdentifier() calls in:
- internal/diff/policy.go: CREATE POLICY and ALTER POLICY
- internal/diff/table.go: DROP POLICY statements

Enhanced add_policy test case to cover all quoting scenarios.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
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.

Policies dumped without quoted names

1 participant