Skip to content

Comments

fix: quote camelCase column names in online NOT NULL rewrite DDL (#313)#315

Merged
tianzhou merged 1 commit intomainfrom
fix/issue-313-camelcase-column-quoting
Feb 23, 2026
Merged

fix: quote camelCase column names in online NOT NULL rewrite DDL (#313)#315
tianzhou merged 1 commit intomainfrom
fix/issue-313-camelcase-column-quoting

Conversation

@tianzhou
Copy link
Contributor

Summary

  • Fixed missing identifier quoting for column names in the online SET NOT NULL rewrite path (generateColumnNotNullRewrite in internal/plan/rewrite.go)
  • Column names with uppercase letters (e.g., offersValidUntil) were used unquoted in the generated CHECK constraint expression and ALTER COLUMN ... SET NOT NULL statement, causing PostgreSQL to fold them to lowercase and fail with column "offersvaliduntil" does not exist
  • Added ir.QuoteIdentifier() for the column name in the CHECK expression and SET NOT NULL statement

Fixes #313

Test plan

  • Added test case testdata/diff/online/issue_313_camelcase_column_not_null/ with a table using camelCase column names
  • Run: PGSCHEMA_TEST_FILTER="online/issue_313_camelcase_column_not_null" go test -v ./cmd -run TestPlanAndApply
  • All 14 existing online tests continue to pass: PGSCHEMA_TEST_FILTER="online/" go test -v ./cmd -run TestPlanAndApply

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 23, 2026 14:27
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 a bug where camelCase column names were not properly quoted in the online SET NOT NULL rewrite path, causing PostgreSQL to fold them to lowercase and fail with "column does not exist" errors. The fix adds ir.QuoteIdentifier() calls for column names in the generated CHECK constraint expression and ALTER COLUMN statement.

Changes:

  • Fixed missing identifier quoting for column names in generateColumnNotNullRewrite function
  • Added comprehensive test case with camelCase column names to validate 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 Added ir.QuoteIdentifier() for column names in CHECK constraint and SET NOT NULL statements
testdata/diff/online/issue_313_camelcase_column_not_null/old.sql Test schema with camelCase column before adding NOT NULL constraint
testdata/diff/online/issue_313_camelcase_column_not_null/new.sql Test schema with camelCase column after adding NOT NULL constraint
testdata/diff/online/issue_313_camelcase_column_not_null/diff.sql Expected simple migration SQL with quoted column name
testdata/diff/online/issue_313_camelcase_column_not_null/plan.sql Expected online migration SQL with quoted column names
testdata/diff/online/issue_313_camelcase_column_not_null/plan.json Expected JSON plan output with quoted column names
testdata/diff/online/issue_313_camelcase_column_not_null/plan.txt Expected human-readable plan output

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

@greptile-apps
Copy link

greptile-apps bot commented Feb 23, 2026

Greptile Summary

Fixed missing identifier quoting for camelCase column names in online SET NOT NULL migration rewrite logic. The bug caused PostgreSQL to fold unquoted identifiers to lowercase, resulting in "column does not exist" errors.

Changes made:

  • Added ir.QuoteIdentifier() for column names in generateColumnNotNullRewrite function (lines 301, 305, 313)
  • Column names are now properly quoted in CHECK constraint expression and ALTER COLUMN statement
  • Constraint names (which inherit uppercase from column names) were already being quoted correctly

Test coverage:

  • New test case testdata/diff/online/issue_313_camelcase_column_not_null/ validates the fix
  • Test uses table "Planning" with camelCase column "offersValidUntil"
  • Verifies all 4 online rewrite steps generate properly quoted SQL
  • All 14 existing online tests continue to pass

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The fix is minimal, targeted, and correct - adds two ir.QuoteIdentifier() calls to handle camelCase columns. The constraint name quoting was already correct. Comprehensive test coverage validates the fix, and all existing tests pass.
  • No files require special attention

Important Files Changed

Filename Overview
internal/plan/rewrite.go Fixed identifier quoting for camelCase column names in online NOT NULL rewrite logic by adding ir.QuoteIdentifier() calls
testdata/diff/online/issue_313_camelcase_column_not_null/plan.sql Expected online migration plan with properly quoted identifiers in all 4 rewrite steps
testdata/diff/online/issue_313_camelcase_column_not_null/plan.json JSON test fixture verifying all 4 online rewrite steps have properly quoted identifiers

Last reviewed commit: 4b9e009

@tianzhou tianzhou merged commit 15684cc into main Feb 23, 2026
6 checks passed
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.

Issue with camelcase column names

1 participant