Skip to content

Conversation

@PadenZach
Copy link
Contributor

Add test cases to test for these, fixes #270

Example of this fixing the issue:

Summary by type:
  tables: 1 to modify

Tables:
  ~ ex
    ~ ID (column)

DDL to be executed:
--------------------------------------------------

ALTER TABLE ex ALTER COLUMN "ID" TYPE bigint;

Do you want to apply these changes? (yes/no): yes

Applying changes...
time=2026-01-30T15:31:41.750-06:00 level=DEBUG msg="Attempting database connection" host=localhost port=5432 database=postgres user=postgres sslmode=prefer application_name=pgschema
time=2026-01-30T15:31:41.765-06:00 level=DEBUG msg="Database connection established successfully"
time=2026-01-30T15:31:41.765-06:00 level=DEBUG msg="Executing SQL" description="set search_path to target schema" sql="SET search_path TO example, public"
time=2026-01-30T15:31:41.766-06:00 level=DEBUG msg="SQL execution succeeded" description="set search_path to target schema"
Set search_path to: example, public

Executing group 1/1...
  Executing 1 statements in implicit transaction
time=2026-01-30T15:31:41.766-06:00 level=DEBUG msg="Executing SQL" description="execute 1 statements in group 1" sql="ALTER TABLE ex ALTER COLUMN \"ID\" TYPE bigint;;"
time=2026-01-30T15:31:41.778-06:00 level=DEBUG msg="SQL execution succeeded" description="execute 1 statements in group 1"
Changes applied successfully!

Add test cases to test for these, fixes pgplex#270
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

Fixes incorrect SQL generation when table columns use quoted identifiers (e.g., "ID"), ensuring generated ALTER/COLUMN COMMENT statements quote identifiers consistently (addresses #270).

Changes:

  • Quote column identifiers in ALTER COLUMN statements (type/default/nullability changes).
  • Quote column identifiers in COMMENT ON COLUMN statements (both create-time and alter-time).
  • Add golden diff test cases for ALTER COLUMN + column comments with quoted identifiers.

Reviewed changes

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

Show a summary per file
File Description
internal/diff/column.go Applies ir.QuoteIdentifier to column names in generated ALTER TABLE ... ALTER COLUMN ... statements (including USING expressions).
internal/diff/table.go Applies ir.QuoteIdentifier to column names in generated COMMENT ON COLUMN ... statements (create + alter paths).
testdata/diff/create_table/alter_column_quoted_identifier/old.sql Adds baseline schema for quoted-column type-change test.
testdata/diff/create_table/alter_column_quoted_identifier/new.sql Adds target schema for quoted-column type-change test.
testdata/diff/create_table/alter_column_quoted_identifier/diff.sql Golden expected diff SQL for quoted-column type-change.
testdata/diff/create_table/alter_column_quoted_identifier/plan.sql Golden expected plan SQL output for quoted-column type-change.
testdata/diff/create_table/alter_column_quoted_identifier/plan.txt Golden expected human-readable plan output for quoted-column type-change.
testdata/diff/create_table/alter_column_quoted_identifier/plan.json Golden expected JSON plan output for quoted-column type-change.
testdata/diff/comment/column_comment_quoted_identifier/old.sql Adds baseline schema for quoted-column comment test.
testdata/diff/comment/column_comment_quoted_identifier/new.sql Adds target schema for quoted-column comment test.
testdata/diff/comment/column_comment_quoted_identifier/diff.sql Golden expected diff SQL for quoted-column comment.
testdata/diff/comment/column_comment_quoted_identifier/plan.sql Golden expected plan SQL output for quoted-column comment.
testdata/diff/comment/column_comment_quoted_identifier/plan.txt Golden expected human-readable plan output for quoted-column comment.
testdata/diff/comment/column_comment_quoted_identifier/plan.json Golden expected JSON plan output for quoted-column comment.

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

Copy link
Contributor

@tianzhou tianzhou left a comment

Choose a reason for hiding this comment

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

LGTM. Thank for the contributions

@tianzhou tianzhou merged commit cc76ca3 into pgplex:main Jan 31, 2026
7 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.

Altering tables with quoted identifiers does not quote them

2 participants