fix: add proper quoting for camelCase columns in CREATE INDEX#23
fix: add proper quoting for camelCase columns in CREATE INDEX#23screenfluent wants to merge 3 commits intopgplex:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where CREATE INDEX statements were not properly quoting camelCase column names, causing PostgreSQL to lowercase them and resulting in "column does not exist" errors.
- Added
util.QuoteIdentifier()calls to properly quote column names in index generation - Fixed both regular CREATE INDEX and CREATE INDEX CONCURRENTLY statements
- Added comprehensive test coverage for camelCase columns, mixed case scenarios, and reserved words
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/diff/index.go | Fixed column name quoting in regular CREATE INDEX statements |
| internal/plan/rewrite.go | Fixed column name quoting in CREATE INDEX CONCURRENTLY statements |
| internal/diff/index_test.go | Added comprehensive test cases for camelCase column handling |
| testdata/diff/online/add_camelcase_index/* | Test data files demonstrating the fix for camelCase index creation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
df777ec to
5759a93
Compare
719fc98 to
26b6049
Compare
There was a problem hiding this comment.
Please re-sync the main branch. I have removed those files there. Thanks for catching this.
| part := col.Name | ||
| var part string | ||
| // Don't quote functional expressions | ||
| if strings.Contains(col.Name, "(") || strings.Contains(col.Name, ")") { |
There was a problem hiding this comment.
I am wondering if we can handle quotation in the ir module
https://github.com/pgschema/pgschema/blob/main/internal/ir/ir.go#L201
Problem: CREATE INDEX statements were generating column names without quotes, causing PostgreSQL to lowercase them (assignedTo -> assignedto). Solution: Use util.QuoteIdentifier() for simple column names, but avoid quoting functional expressions like lower(email) or upper(firstName). Changes: - internal/diff/index.go: Fixed regular CREATE INDEX statements - internal/plan/rewrite.go: Fixed CREATE INDEX CONCURRENTLY statements - Added comprehensive tests for camelCase, functional indexes, and reserved words This ensures: - camelCase columns are quoted: "assignedTo" - lowercase columns remain unquoted: email - reserved words are quoted: "order", "user" - functional expressions remain unquoted: lower(email)
…TE INDEX Problem: CREATE INDEX statements were missing quotes for: 1. CamelCase column names (assignedTo -> assignedto) 2. CamelCase index names (idx_invite_assignedTo -> idx_invite_assignedto) Solution: Use util.QuoteIdentifier() for: - Index names with camelCase - Simple column names (but not functional expressions) Changes: - internal/diff/index.go: Quote index names and column names - internal/plan/rewrite.go: Quote index names for CONCURRENTLY - Added comprehensive tests for all scenarios - Fixed test data to expect quoted index names This ensures proper quoting while preserving functional indexes like lower(email)
26b6049 to
99583a6
Compare
All CREATE INDEX CONCURRENTLY tests now use lower() function in wait queries to properly handle case-insensitive index name comparisons in PostgreSQL
eb7c30c to
0f15948
Compare
|
The codebase has been changed significantly and make this PR not mergeable. |
Problem
CREATE INDEX statements were generating column names without quotes, causing PostgreSQL to lowercase them. This breaks indexes on tables with camelCase columns.
Example of the bug:
Solution
Use
util.QuoteIdentifier()for column names in index generation. This ensures:"assignedTo"email"order","user"Changes
Testing
All new tests pass:
Tested on real project with camelCase columns - confirmed working correctly.
Related Issues
This is a different issue from #17/#22 (constraint column ordering). This one specifically fixes missing quotes in index column names.