fix: reserved keyword not quoted in online rewrite DDL (#286)#291
Merged
fix: reserved keyword not quoted in online rewrite DDL (#286)#291
Conversation
The `getTableNameWithSchema` helper in `internal/plan/rewrite.go` was returning raw table names without quoting, causing reserved keywords like `order` to produce invalid SQL in online rewrite operations (CREATE INDEX CONCURRENTLY, constraint rewrites, etc.). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where reserved keyword table names (like order) were not being properly quoted in online rewrite DDL operations such as CREATE INDEX CONCURRENTLY, foreign key rewrites, constraint rewrites, NOT NULL rewrites, and identity column rewrites. The fix ensures that getTableNameWithSchema in internal/plan/rewrite.go properly quotes identifiers using ir.QuoteIdentifier(), matching the behavior already implemented in internal/diff/diff.go.
Changes:
- Modified
getTableNameWithSchemahelper function to quote table and schema names usingir.QuoteIdentifier() - Added comprehensive test case with a table named
order(a reserved keyword) to verify the fix
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/plan/rewrite.go | Fixed getTableNameWithSchema to quote table and schema identifiers, preventing SQL syntax errors with reserved keywords |
| testdata/diff/online/issue_286_reserved_keyword_quoting/old.sql | Test setup: defines a table named order (reserved keyword) with basic columns |
| testdata/diff/online/issue_286_reserved_keyword_quoting/new.sql | Test setup: adds a column with FK constraint and index to the order table |
| testdata/diff/online/issue_286_reserved_keyword_quoting/plan.txt | Expected output: verifies table name is quoted in all DDL statements |
| testdata/diff/online/issue_286_reserved_keyword_quoting/plan.sql | Expected output: verifies table name is quoted in SQL plan |
| testdata/diff/online/issue_286_reserved_keyword_quoting/plan.json | Expected output: verifies table name is quoted in JSON plan |
| testdata/diff/online/issue_286_reserved_keyword_quoting/diff.sql | Expected output: verifies table name is quoted in diff SQL |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getTableNameWithSchemahelper ininternal/plan/rewrite.gowas returning raw table/schema names without callingir.QuoteIdentifier(), causing reserved keywords likeorderto produce invalid SQL in online rewrite operations (CREATE INDEX CONCURRENTLY, constraint rewrites, FK rewrites, NOT NULL rewrites, identity column rewrites)internal/diff/diff.goalready quoted correctly, so only the plan rewrite path was affectedFixes #286
Test plan
testdata/diff/online/issue_286_reserved_keyword_quoting/test case with a table namedorder(reserved keyword) that gets a new column with FK and an indexPGSCHEMA_TEST_FILTER="online/issue_286_reserved_keyword_quoting" go test -v ./internal/diff -run TestDiffFromFilesPGSCHEMA_TEST_FILTER="online/issue_286_reserved_keyword_quoting" go test -v ./cmd -run TestPlanAndApplyPGSCHEMA_TEST_FILTER="online/" go test -v ./cmd -run TestPlanAndApply🤖 Generated with Claude Code