fix: always schema-qualify table in COMMENT ON COLUMN (#502)#504
Conversation
When a table name matches the target schema (e.g. table "public" in schema "public"), stripSchemaQualifications strips the table qualifier thinking it is a schema prefix, producing invalid SQL like "COMMENT ON COLUMN column IS ...". Always emitting the schema-qualified form (schema.table.column) ensures the schema prefix can be safely stripped while preserving the table.column reference. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR fixes a bug where
Confidence Score: 5/5The change is safe to merge — it correctly fixes a narrow SQL-generation bug without any collateral risk to the broader diff or plan pipeline. All three COMMENT ON COLUMN emission sites are updated consistently. The fix is logically sound: always emitting schema.table lets stripSchemaQualifications strip exactly one prefix level, regardless of whether the table name coincidentally matches the schema name. The golden test files are fully updated and a dedicated regression fixture is added. No other code paths are affected. No files require special attention. Important Files Changed
Reviews (1): Last reviewed commit: "fix: always schema-qualify table in COMM..." | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
This PR fixes a dump→plan round-trip failure for COMMENT ON COLUMN when a table name matches the target schema name (Issue #502) by ensuring COMMENT ON COLUMN statements are emitted with a schema-qualified table reference (i.e., schema.table.column), allowing stripSchemaQualifications to remove only the schema prefix without misinterpreting table.column as schema.object.
Changes:
- Always emit
COMMENT ON COLUMNusingschema.table.columnininternal/diff/table.go(create tables, added columns, modified column comments). - Add a regression fixture covering the “table name equals schema name” case.
- Update existing golden outputs to reflect the new
public.-qualifiedCOMMENT ON COLUMNSQL.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/diff/table.go | Emits schema-qualified table names for COMMENT ON COLUMN to prevent stripSchemaQualifications from stripping the wrong qualifier. |
| testdata/diff/create_table/add_table_like/plan.txt | Updates golden plan output to include public. qualification for column comments. |
| testdata/diff/create_table/add_table_like/plan.sql | Updates golden SQL output to include public. qualification for column comments. |
| testdata/diff/create_table/add_table_like/plan.json | Updates golden JSON output to include public. qualification for column comments. |
| testdata/diff/create_table/add_table_like/diff.sql | Updates golden diff output to include public. qualification for column comments. |
| testdata/diff/comment/mixed_comments/plan.txt | Updates golden plan output to include public. qualification for column comments. |
| testdata/diff/comment/mixed_comments/plan.sql | Updates golden SQL output to include public. qualification for column comments. |
| testdata/diff/comment/mixed_comments/plan.json | Updates golden JSON output to include public. qualification for column comments. |
| testdata/diff/comment/mixed_comments/diff.sql | Updates golden diff output to include public. qualification for column comments. |
| testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.txt | Adds regression fixture demonstrating correct handling when table name matches schema name. |
| testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.sql | Adds regression fixture SQL output for the new edge case. |
| testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.json | Adds regression fixture JSON output for the new edge case. |
| testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/old.sql | Adds old-state SQL for the regression fixture. |
| testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/new.sql | Adds new-state SQL (with column comments) for the regression fixture. |
| testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/diff.sql | Adds expected diff SQL for the regression fixture. |
| testdata/diff/comment/column_comment_quoted_identifier/plan.txt | Updates golden output to include public. qualification for quoted-column comment case. |
| testdata/diff/comment/column_comment_quoted_identifier/plan.sql | Updates golden SQL output to include public. qualification for quoted-column comment case. |
| testdata/diff/comment/column_comment_quoted_identifier/plan.json | Updates golden JSON output to include public. qualification for quoted-column comment case. |
| testdata/diff/comment/column_comment_quoted_identifier/diff.sql | Updates golden diff output to include public. qualification for quoted-column comment case. |
| testdata/diff/comment/add_column_comments/plan.txt | Updates golden plan output to include public. qualification for column comments. |
| testdata/diff/comment/add_column_comments/plan.sql | Updates golden SQL output to include public. qualification for column comments. |
| testdata/diff/comment/add_column_comments/plan.json | Updates golden JSON output to include public. qualification for column comments. |
| testdata/diff/comment/add_column_comments/diff.sql | Updates golden diff output to include public. qualification for column comments. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Only schema-qualify table names in COMMENT ON COLUMN when the table name matches the target schema (the case where stripSchemaQualifications would mangle the table.column reference). This avoids changing dump output format for all other cases while still fixing the issue #502 bug. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
COMMENT ON COLUMNemissions so thatstripSchemaQualificationscan safely strip the schema prefix without mangling thetable.columnreferencepublicin schemapublic), which causedstripSchemaQualificationsto strip the table qualifier producing invalid SQLCOMMENT ON COLUMNemission sites ininternal/diff/table.goand all golden test filesTest plan
comment/issue_502_column_comment_table_name_matches_schematest fixture with table namedpublicin schemapublicpublic.prefix)Closes #502
🤖 Generated with Claude Code