From 6f5c17cf046efda2733d003b46bbd74eb48b7a18 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Mon, 6 Jul 2026 01:02:01 -0700 Subject: [PATCH 1/2] fix: always schema-qualify table in COMMENT ON COLUMN (#502) 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 --- internal/diff/table.go | 8 +++--- .../diff/comment/add_column_comments/diff.sql | 8 +++--- .../comment/add_column_comments/plan.json | 8 +++--- .../diff/comment/add_column_comments/plan.sql | 8 +++--- .../diff/comment/add_column_comments/plan.txt | 8 +++--- .../column_comment_quoted_identifier/diff.sql | 2 +- .../plan.json | 2 +- .../column_comment_quoted_identifier/plan.sql | 2 +- .../column_comment_quoted_identifier/plan.txt | 2 +- .../diff.sql | 3 +++ .../new.sql | 7 +++++ .../old.sql | 4 +++ .../plan.json | 26 +++++++++++++++++++ .../plan.sql | 3 +++ .../plan.txt | 16 ++++++++++++ testdata/diff/comment/mixed_comments/diff.sql | 22 ++++++++-------- .../diff/comment/mixed_comments/plan.json | 22 ++++++++-------- testdata/diff/comment/mixed_comments/plan.sql | 22 ++++++++-------- testdata/diff/comment/mixed_comments/plan.txt | 22 ++++++++-------- .../diff/create_table/add_table_like/diff.sql | 2 +- .../create_table/add_table_like/plan.json | 2 +- .../diff/create_table/add_table_like/plan.sql | 2 +- .../diff/create_table/add_table_like/plan.txt | 2 +- 23 files changed, 132 insertions(+), 71 deletions(-) create mode 100644 testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/diff.sql create mode 100644 testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/new.sql create mode 100644 testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/old.sql create mode 100644 testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.json create mode 100644 testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.sql create mode 100644 testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.txt diff --git a/internal/diff/table.go b/internal/diff/table.go index f2fedf3f..8f560897 100644 --- a/internal/diff/table.go +++ b/internal/diff/table.go @@ -456,7 +456,9 @@ func generateCreateTablesSQL( // Add column comments for _, column := range table.Columns { if column.Comment != "" { - tableName := qualifyEntityNameMode(table.Schema, table.Name, targetSchema, collector.qualifySchema) + // Always schema-qualify so stripSchemaQualifications can safely + // remove the schema prefix without mangling the table.column part. + tableName := fmt.Sprintf("%s.%s", ir.QuoteIdentifier(table.Schema), ir.QuoteIdentifier(table.Name)) sql := fmt.Sprintf("COMMENT ON COLUMN %s.%s IS %s;", tableName, ir.QuoteIdentifier(column.Name), quoteString(column.Comment)) // Create context for this statement @@ -1134,7 +1136,7 @@ func (td *tableDiff) generateAlterTableStatements(targetSchema string, collector // Add comments for new columns for _, column := range td.AddedColumns { if column.Comment != "" { - tableName := getTableNameWithSchema(td.Table.Schema, td.Table.Name, targetSchema) + tableName := fmt.Sprintf("%s.%s", ir.QuoteIdentifier(td.Table.Schema), ir.QuoteIdentifier(td.Table.Name)) sql := fmt.Sprintf("COMMENT ON COLUMN %s.%s IS %s;", tableName, ir.QuoteIdentifier(column.Name), quoteString(column.Comment)) context := &diffContext{ @@ -1603,7 +1605,7 @@ func (td *tableDiff) generateAlterTableStatements(targetSchema string, collector // Handle column comment changes for _, colDiff := range td.ModifiedColumns { if colDiff.Old.Comment != colDiff.New.Comment { - tableName := getTableNameWithSchema(td.Table.Schema, td.Table.Name, targetSchema) + tableName := fmt.Sprintf("%s.%s", ir.QuoteIdentifier(td.Table.Schema), ir.QuoteIdentifier(td.Table.Name)) var sql string if colDiff.New.Comment == "" { sql = fmt.Sprintf("COMMENT ON COLUMN %s.%s IS NULL;", tableName, ir.QuoteIdentifier(colDiff.New.Name)) diff --git a/testdata/diff/comment/add_column_comments/diff.sql b/testdata/diff/comment/add_column_comments/diff.sql index 0a8c87f5..d48b36e8 100644 --- a/testdata/diff/comment/add_column_comments/diff.sql +++ b/testdata/diff/comment/add_column_comments/diff.sql @@ -1,7 +1,7 @@ -COMMENT ON COLUMN products.id IS 'Unique product identifier'; +COMMENT ON COLUMN public.products.id IS 'Unique product identifier'; -COMMENT ON COLUMN products.name IS 'Product display name'; +COMMENT ON COLUMN public.products.name IS 'Product display name'; -COMMENT ON COLUMN products.price IS 'Product price in USD'; +COMMENT ON COLUMN public.products.price IS 'Product price in USD'; -COMMENT ON COLUMN products.created_at IS 'Timestamp when product was added'; +COMMENT ON COLUMN public.products.created_at IS 'Timestamp when product was added'; diff --git a/testdata/diff/comment/add_column_comments/plan.json b/testdata/diff/comment/add_column_comments/plan.json index 355d3789..423e801c 100644 --- a/testdata/diff/comment/add_column_comments/plan.json +++ b/testdata/diff/comment/add_column_comments/plan.json @@ -9,25 +9,25 @@ { "steps": [ { - "sql": "COMMENT ON COLUMN products.id IS 'Unique product identifier';", + "sql": "COMMENT ON COLUMN public.products.id IS 'Unique product identifier';", "type": "table.column.comment", "operation": "alter", "path": "public.products.id" }, { - "sql": "COMMENT ON COLUMN products.name IS 'Product display name';", + "sql": "COMMENT ON COLUMN public.products.name IS 'Product display name';", "type": "table.column.comment", "operation": "alter", "path": "public.products.name" }, { - "sql": "COMMENT ON COLUMN products.price IS 'Product price in USD';", + "sql": "COMMENT ON COLUMN public.products.price IS 'Product price in USD';", "type": "table.column.comment", "operation": "alter", "path": "public.products.price" }, { - "sql": "COMMENT ON COLUMN products.created_at IS 'Timestamp when product was added';", + "sql": "COMMENT ON COLUMN public.products.created_at IS 'Timestamp when product was added';", "type": "table.column.comment", "operation": "alter", "path": "public.products.created_at" diff --git a/testdata/diff/comment/add_column_comments/plan.sql b/testdata/diff/comment/add_column_comments/plan.sql index 0a8c87f5..d48b36e8 100644 --- a/testdata/diff/comment/add_column_comments/plan.sql +++ b/testdata/diff/comment/add_column_comments/plan.sql @@ -1,7 +1,7 @@ -COMMENT ON COLUMN products.id IS 'Unique product identifier'; +COMMENT ON COLUMN public.products.id IS 'Unique product identifier'; -COMMENT ON COLUMN products.name IS 'Product display name'; +COMMENT ON COLUMN public.products.name IS 'Product display name'; -COMMENT ON COLUMN products.price IS 'Product price in USD'; +COMMENT ON COLUMN public.products.price IS 'Product price in USD'; -COMMENT ON COLUMN products.created_at IS 'Timestamp when product was added'; +COMMENT ON COLUMN public.products.created_at IS 'Timestamp when product was added'; diff --git a/testdata/diff/comment/add_column_comments/plan.txt b/testdata/diff/comment/add_column_comments/plan.txt index b61e65d0..3e4f5967 100644 --- a/testdata/diff/comment/add_column_comments/plan.txt +++ b/testdata/diff/comment/add_column_comments/plan.txt @@ -13,10 +13,10 @@ Tables: DDL to be executed: -------------------------------------------------- -COMMENT ON COLUMN products.id IS 'Unique product identifier'; +COMMENT ON COLUMN public.products.id IS 'Unique product identifier'; -COMMENT ON COLUMN products.name IS 'Product display name'; +COMMENT ON COLUMN public.products.name IS 'Product display name'; -COMMENT ON COLUMN products.price IS 'Product price in USD'; +COMMENT ON COLUMN public.products.price IS 'Product price in USD'; -COMMENT ON COLUMN products.created_at IS 'Timestamp when product was added'; +COMMENT ON COLUMN public.products.created_at IS 'Timestamp when product was added'; diff --git a/testdata/diff/comment/column_comment_quoted_identifier/diff.sql b/testdata/diff/comment/column_comment_quoted_identifier/diff.sql index a55753ec..800e5f97 100644 --- a/testdata/diff/comment/column_comment_quoted_identifier/diff.sql +++ b/testdata/diff/comment/column_comment_quoted_identifier/diff.sql @@ -1 +1 @@ -COMMENT ON COLUMN ex."ID" IS 'Primary identifier'; +COMMENT ON COLUMN public.ex."ID" IS 'Primary identifier'; diff --git a/testdata/diff/comment/column_comment_quoted_identifier/plan.json b/testdata/diff/comment/column_comment_quoted_identifier/plan.json index 83187cd1..237b6424 100644 --- a/testdata/diff/comment/column_comment_quoted_identifier/plan.json +++ b/testdata/diff/comment/column_comment_quoted_identifier/plan.json @@ -9,7 +9,7 @@ { "steps": [ { - "sql": "COMMENT ON COLUMN ex.\"ID\" IS 'Primary identifier';", + "sql": "COMMENT ON COLUMN public.ex.\"ID\" IS 'Primary identifier';", "type": "table.column.comment", "operation": "alter", "path": "public.ex.ID" diff --git a/testdata/diff/comment/column_comment_quoted_identifier/plan.sql b/testdata/diff/comment/column_comment_quoted_identifier/plan.sql index a55753ec..800e5f97 100644 --- a/testdata/diff/comment/column_comment_quoted_identifier/plan.sql +++ b/testdata/diff/comment/column_comment_quoted_identifier/plan.sql @@ -1 +1 @@ -COMMENT ON COLUMN ex."ID" IS 'Primary identifier'; +COMMENT ON COLUMN public.ex."ID" IS 'Primary identifier'; diff --git a/testdata/diff/comment/column_comment_quoted_identifier/plan.txt b/testdata/diff/comment/column_comment_quoted_identifier/plan.txt index 21265294..4ea8bdb1 100644 --- a/testdata/diff/comment/column_comment_quoted_identifier/plan.txt +++ b/testdata/diff/comment/column_comment_quoted_identifier/plan.txt @@ -10,4 +10,4 @@ Tables: DDL to be executed: -------------------------------------------------- -COMMENT ON COLUMN ex."ID" IS 'Primary identifier'; +COMMENT ON COLUMN public.ex."ID" IS 'Primary identifier'; diff --git a/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/diff.sql b/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/diff.sql new file mode 100644 index 00000000..37307f45 --- /dev/null +++ b/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/diff.sql @@ -0,0 +1,3 @@ +COMMENT ON COLUMN public.public.id IS 'Primary key'; + +COMMENT ON COLUMN public.public.name IS 'Display name'; diff --git a/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/new.sql b/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/new.sql new file mode 100644 index 00000000..658ecab2 --- /dev/null +++ b/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/new.sql @@ -0,0 +1,7 @@ +CREATE TABLE public ( + id SERIAL PRIMARY KEY, + name TEXT NOT NULL +); + +COMMENT ON COLUMN public.public.id IS 'Primary key'; +COMMENT ON COLUMN public.public.name IS 'Display name'; diff --git a/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/old.sql b/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/old.sql new file mode 100644 index 00000000..76ca2b2d --- /dev/null +++ b/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/old.sql @@ -0,0 +1,4 @@ +CREATE TABLE public ( + id SERIAL PRIMARY KEY, + name TEXT NOT NULL +); diff --git a/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.json b/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.json new file mode 100644 index 00000000..a4848969 --- /dev/null +++ b/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.json @@ -0,0 +1,26 @@ +{ + "version": "1.0.0", + "pgschema_version": "1.11.1", + "created_at": "1970-01-01T00:00:00Z", + "source_fingerprint": { + "hash": "c8aff322ec8a9d064fda21505117c0b296ba9669f7503ad7d8055d7f8f1f5ff7" + }, + "groups": [ + { + "steps": [ + { + "sql": "COMMENT ON COLUMN public.public.id IS 'Primary key';", + "type": "table.column.comment", + "operation": "alter", + "path": "public.public.id" + }, + { + "sql": "COMMENT ON COLUMN public.public.name IS 'Display name';", + "type": "table.column.comment", + "operation": "alter", + "path": "public.public.name" + } + ] + } + ] +} diff --git a/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.sql b/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.sql new file mode 100644 index 00000000..37307f45 --- /dev/null +++ b/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.sql @@ -0,0 +1,3 @@ +COMMENT ON COLUMN public.public.id IS 'Primary key'; + +COMMENT ON COLUMN public.public.name IS 'Display name'; diff --git a/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.txt b/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.txt new file mode 100644 index 00000000..affa6453 --- /dev/null +++ b/testdata/diff/comment/issue_502_column_comment_table_name_matches_schema/plan.txt @@ -0,0 +1,16 @@ +Plan: 1 to modify. + +Summary by type: + tables: 1 to modify + +Tables: + ~ public + ~ id (column.comment) + ~ name (column.comment) + +DDL to be executed: +-------------------------------------------------- + +COMMENT ON COLUMN public.public.id IS 'Primary key'; + +COMMENT ON COLUMN public.public.name IS 'Display name'; diff --git a/testdata/diff/comment/mixed_comments/diff.sql b/testdata/diff/comment/mixed_comments/diff.sql index 9fdf7197..a38ecb4c 100644 --- a/testdata/diff/comment/mixed_comments/diff.sql +++ b/testdata/diff/comment/mixed_comments/diff.sql @@ -1,32 +1,32 @@ COMMENT ON TABLE categories IS 'Hierarchical category system for posts'; -COMMENT ON COLUMN categories.id IS 'Category unique identifier'; +COMMENT ON COLUMN public.categories.id IS 'Category unique identifier'; -COMMENT ON COLUMN categories.name IS 'Category display name'; +COMMENT ON COLUMN public.categories.name IS 'Category display name'; -COMMENT ON COLUMN categories.description IS 'Optional category description'; +COMMENT ON COLUMN public.categories.description IS 'Optional category description'; -COMMENT ON COLUMN categories.parent_id IS 'Parent category for hierarchical structure'; +COMMENT ON COLUMN public.categories.parent_id IS 'Parent category for hierarchical structure'; -COMMENT ON COLUMN categories.created_at IS 'Category creation timestamp'; +COMMENT ON COLUMN public.categories.created_at IS 'Category creation timestamp'; COMMENT ON INDEX idx_categories_parent IS 'Index for hierarchical category queries'; ALTER TABLE posts ADD COLUMN views integer DEFAULT 0; -COMMENT ON COLUMN posts.views IS 'Number of post views'; +COMMENT ON COLUMN public.posts.views IS 'Number of post views'; COMMENT ON TABLE posts IS 'Blog posts and articles'; -COMMENT ON COLUMN posts.id IS 'Unique post identifier'; +COMMENT ON COLUMN public.posts.id IS 'Unique post identifier'; -COMMENT ON COLUMN posts.title IS 'Post title, max 200 characters'; +COMMENT ON COLUMN public.posts.title IS 'Post title, max 200 characters'; -COMMENT ON COLUMN posts.content IS 'Post body in markdown format'; +COMMENT ON COLUMN public.posts.content IS 'Post body in markdown format'; -COMMENT ON COLUMN posts.author_id IS 'Foreign key to users table'; +COMMENT ON COLUMN public.posts.author_id IS 'Foreign key to users table'; -COMMENT ON COLUMN posts.published_at IS 'Publication timestamp, NULL for drafts'; +COMMENT ON COLUMN public.posts.published_at IS 'Publication timestamp, NULL for drafts'; COMMENT ON INDEX idx_posts_author IS 'Index for finding posts by author'; diff --git a/testdata/diff/comment/mixed_comments/plan.json b/testdata/diff/comment/mixed_comments/plan.json index 8cbaeca3..db4520ac 100644 --- a/testdata/diff/comment/mixed_comments/plan.json +++ b/testdata/diff/comment/mixed_comments/plan.json @@ -15,31 +15,31 @@ "path": "public.categories" }, { - "sql": "COMMENT ON COLUMN categories.id IS 'Category unique identifier';", + "sql": "COMMENT ON COLUMN public.categories.id IS 'Category unique identifier';", "type": "table.column.comment", "operation": "alter", "path": "public.categories.id" }, { - "sql": "COMMENT ON COLUMN categories.name IS 'Category display name';", + "sql": "COMMENT ON COLUMN public.categories.name IS 'Category display name';", "type": "table.column.comment", "operation": "alter", "path": "public.categories.name" }, { - "sql": "COMMENT ON COLUMN categories.description IS 'Optional category description';", + "sql": "COMMENT ON COLUMN public.categories.description IS 'Optional category description';", "type": "table.column.comment", "operation": "alter", "path": "public.categories.description" }, { - "sql": "COMMENT ON COLUMN categories.parent_id IS 'Parent category for hierarchical structure';", + "sql": "COMMENT ON COLUMN public.categories.parent_id IS 'Parent category for hierarchical structure';", "type": "table.column.comment", "operation": "alter", "path": "public.categories.parent_id" }, { - "sql": "COMMENT ON COLUMN categories.created_at IS 'Category creation timestamp';", + "sql": "COMMENT ON COLUMN public.categories.created_at IS 'Category creation timestamp';", "type": "table.column.comment", "operation": "alter", "path": "public.categories.created_at" @@ -57,7 +57,7 @@ "path": "public.posts.views" }, { - "sql": "COMMENT ON COLUMN posts.views IS 'Number of post views';", + "sql": "COMMENT ON COLUMN public.posts.views IS 'Number of post views';", "type": "table.column.comment", "operation": "create", "path": "public.posts.views" @@ -69,31 +69,31 @@ "path": "public.posts" }, { - "sql": "COMMENT ON COLUMN posts.id IS 'Unique post identifier';", + "sql": "COMMENT ON COLUMN public.posts.id IS 'Unique post identifier';", "type": "table.column.comment", "operation": "alter", "path": "public.posts.id" }, { - "sql": "COMMENT ON COLUMN posts.title IS 'Post title, max 200 characters';", + "sql": "COMMENT ON COLUMN public.posts.title IS 'Post title, max 200 characters';", "type": "table.column.comment", "operation": "alter", "path": "public.posts.title" }, { - "sql": "COMMENT ON COLUMN posts.content IS 'Post body in markdown format';", + "sql": "COMMENT ON COLUMN public.posts.content IS 'Post body in markdown format';", "type": "table.column.comment", "operation": "alter", "path": "public.posts.content" }, { - "sql": "COMMENT ON COLUMN posts.author_id IS 'Foreign key to users table';", + "sql": "COMMENT ON COLUMN public.posts.author_id IS 'Foreign key to users table';", "type": "table.column.comment", "operation": "alter", "path": "public.posts.author_id" }, { - "sql": "COMMENT ON COLUMN posts.published_at IS 'Publication timestamp, NULL for drafts';", + "sql": "COMMENT ON COLUMN public.posts.published_at IS 'Publication timestamp, NULL for drafts';", "type": "table.column.comment", "operation": "alter", "path": "public.posts.published_at" diff --git a/testdata/diff/comment/mixed_comments/plan.sql b/testdata/diff/comment/mixed_comments/plan.sql index 9fdf7197..a38ecb4c 100644 --- a/testdata/diff/comment/mixed_comments/plan.sql +++ b/testdata/diff/comment/mixed_comments/plan.sql @@ -1,32 +1,32 @@ COMMENT ON TABLE categories IS 'Hierarchical category system for posts'; -COMMENT ON COLUMN categories.id IS 'Category unique identifier'; +COMMENT ON COLUMN public.categories.id IS 'Category unique identifier'; -COMMENT ON COLUMN categories.name IS 'Category display name'; +COMMENT ON COLUMN public.categories.name IS 'Category display name'; -COMMENT ON COLUMN categories.description IS 'Optional category description'; +COMMENT ON COLUMN public.categories.description IS 'Optional category description'; -COMMENT ON COLUMN categories.parent_id IS 'Parent category for hierarchical structure'; +COMMENT ON COLUMN public.categories.parent_id IS 'Parent category for hierarchical structure'; -COMMENT ON COLUMN categories.created_at IS 'Category creation timestamp'; +COMMENT ON COLUMN public.categories.created_at IS 'Category creation timestamp'; COMMENT ON INDEX idx_categories_parent IS 'Index for hierarchical category queries'; ALTER TABLE posts ADD COLUMN views integer DEFAULT 0; -COMMENT ON COLUMN posts.views IS 'Number of post views'; +COMMENT ON COLUMN public.posts.views IS 'Number of post views'; COMMENT ON TABLE posts IS 'Blog posts and articles'; -COMMENT ON COLUMN posts.id IS 'Unique post identifier'; +COMMENT ON COLUMN public.posts.id IS 'Unique post identifier'; -COMMENT ON COLUMN posts.title IS 'Post title, max 200 characters'; +COMMENT ON COLUMN public.posts.title IS 'Post title, max 200 characters'; -COMMENT ON COLUMN posts.content IS 'Post body in markdown format'; +COMMENT ON COLUMN public.posts.content IS 'Post body in markdown format'; -COMMENT ON COLUMN posts.author_id IS 'Foreign key to users table'; +COMMENT ON COLUMN public.posts.author_id IS 'Foreign key to users table'; -COMMENT ON COLUMN posts.published_at IS 'Publication timestamp, NULL for drafts'; +COMMENT ON COLUMN public.posts.published_at IS 'Publication timestamp, NULL for drafts'; COMMENT ON INDEX idx_posts_author IS 'Index for finding posts by author'; diff --git a/testdata/diff/comment/mixed_comments/plan.txt b/testdata/diff/comment/mixed_comments/plan.txt index 6ac14ba1..c519e02e 100644 --- a/testdata/diff/comment/mixed_comments/plan.txt +++ b/testdata/diff/comment/mixed_comments/plan.txt @@ -29,33 +29,33 @@ DDL to be executed: COMMENT ON TABLE categories IS 'Hierarchical category system for posts'; -COMMENT ON COLUMN categories.id IS 'Category unique identifier'; +COMMENT ON COLUMN public.categories.id IS 'Category unique identifier'; -COMMENT ON COLUMN categories.name IS 'Category display name'; +COMMENT ON COLUMN public.categories.name IS 'Category display name'; -COMMENT ON COLUMN categories.description IS 'Optional category description'; +COMMENT ON COLUMN public.categories.description IS 'Optional category description'; -COMMENT ON COLUMN categories.parent_id IS 'Parent category for hierarchical structure'; +COMMENT ON COLUMN public.categories.parent_id IS 'Parent category for hierarchical structure'; -COMMENT ON COLUMN categories.created_at IS 'Category creation timestamp'; +COMMENT ON COLUMN public.categories.created_at IS 'Category creation timestamp'; COMMENT ON INDEX idx_categories_parent IS 'Index for hierarchical category queries'; ALTER TABLE posts ADD COLUMN views integer DEFAULT 0; -COMMENT ON COLUMN posts.views IS 'Number of post views'; +COMMENT ON COLUMN public.posts.views IS 'Number of post views'; COMMENT ON TABLE posts IS 'Blog posts and articles'; -COMMENT ON COLUMN posts.id IS 'Unique post identifier'; +COMMENT ON COLUMN public.posts.id IS 'Unique post identifier'; -COMMENT ON COLUMN posts.title IS 'Post title, max 200 characters'; +COMMENT ON COLUMN public.posts.title IS 'Post title, max 200 characters'; -COMMENT ON COLUMN posts.content IS 'Post body in markdown format'; +COMMENT ON COLUMN public.posts.content IS 'Post body in markdown format'; -COMMENT ON COLUMN posts.author_id IS 'Foreign key to users table'; +COMMENT ON COLUMN public.posts.author_id IS 'Foreign key to users table'; -COMMENT ON COLUMN posts.published_at IS 'Publication timestamp, NULL for drafts'; +COMMENT ON COLUMN public.posts.published_at IS 'Publication timestamp, NULL for drafts'; COMMENT ON INDEX idx_posts_author IS 'Index for finding posts by author'; diff --git a/testdata/diff/create_table/add_table_like/diff.sql b/testdata/diff/create_table/add_table_like/diff.sql index 1a41b787..e78a9750 100644 --- a/testdata/diff/create_table/add_table_like/diff.sql +++ b/testdata/diff/create_table/add_table_like/diff.sql @@ -15,6 +15,6 @@ CREATE TABLE IF NOT EXISTS users ( CONSTRAINT _template_timestamps_check CHECK (created_at <= updated_at) ); -COMMENT ON COLUMN users.created_at IS 'Record creation time'; +COMMENT ON COLUMN public.users.created_at IS 'Record creation time'; CREATE INDEX IF NOT EXISTS users_created_at_idx ON users (created_at); \ No newline at end of file diff --git a/testdata/diff/create_table/add_table_like/plan.json b/testdata/diff/create_table/add_table_like/plan.json index dd33c472..4933bc12 100644 --- a/testdata/diff/create_table/add_table_like/plan.json +++ b/testdata/diff/create_table/add_table_like/plan.json @@ -21,7 +21,7 @@ "path": "public.users" }, { - "sql": "COMMENT ON COLUMN users.created_at IS 'Record creation time';", + "sql": "COMMENT ON COLUMN public.users.created_at IS 'Record creation time';", "type": "table.column.comment", "operation": "create", "path": "public.users.created_at" diff --git a/testdata/diff/create_table/add_table_like/plan.sql b/testdata/diff/create_table/add_table_like/plan.sql index 053c7fce..57563f3d 100644 --- a/testdata/diff/create_table/add_table_like/plan.sql +++ b/testdata/diff/create_table/add_table_like/plan.sql @@ -15,6 +15,6 @@ CREATE TABLE IF NOT EXISTS users ( CONSTRAINT _template_timestamps_check CHECK (created_at <= updated_at) ); -COMMENT ON COLUMN users.created_at IS 'Record creation time'; +COMMENT ON COLUMN public.users.created_at IS 'Record creation time'; CREATE INDEX IF NOT EXISTS users_created_at_idx ON users (created_at); diff --git a/testdata/diff/create_table/add_table_like/plan.txt b/testdata/diff/create_table/add_table_like/plan.txt index 86830933..f2bcd485 100644 --- a/testdata/diff/create_table/add_table_like/plan.txt +++ b/testdata/diff/create_table/add_table_like/plan.txt @@ -29,6 +29,6 @@ CREATE TABLE IF NOT EXISTS users ( CONSTRAINT _template_timestamps_check CHECK (created_at <= updated_at) ); -COMMENT ON COLUMN users.created_at IS 'Record creation time'; +COMMENT ON COLUMN public.users.created_at IS 'Record creation time'; CREATE INDEX IF NOT EXISTS users_created_at_idx ON users (created_at); From 1f31100eb260efad10a7a4d1143907228141bb1e Mon Sep 17 00:00:00 2001 From: tianzhou Date: Mon, 6 Jul 2026 02:14:48 -0700 Subject: [PATCH 2/2] fix: narrow COMMENT ON COLUMN schema-qualification to collision case 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 --- internal/diff/diff.go | 11 ++++++++++ internal/diff/table.go | 8 +++---- .../diff/comment/add_column_comments/diff.sql | 8 +++---- .../comment/add_column_comments/plan.json | 8 +++---- .../diff/comment/add_column_comments/plan.sql | 8 +++---- .../diff/comment/add_column_comments/plan.txt | 8 +++---- .../column_comment_quoted_identifier/diff.sql | 2 +- .../plan.json | 2 +- .../column_comment_quoted_identifier/plan.sql | 2 +- .../column_comment_quoted_identifier/plan.txt | 2 +- testdata/diff/comment/mixed_comments/diff.sql | 22 +++++++++---------- .../diff/comment/mixed_comments/plan.json | 22 +++++++++---------- testdata/diff/comment/mixed_comments/plan.sql | 22 +++++++++---------- testdata/diff/comment/mixed_comments/plan.txt | 22 +++++++++---------- .../diff/create_table/add_table_like/diff.sql | 2 +- .../create_table/add_table_like/plan.json | 2 +- .../diff/create_table/add_table_like/plan.sql | 2 +- .../diff/create_table/add_table_like/plan.txt | 2 +- 18 files changed, 82 insertions(+), 73 deletions(-) diff --git a/internal/diff/diff.go b/internal/diff/diff.go index e23b76ee..8f9e9821 100644 --- a/internal/diff/diff.go +++ b/internal/diff/diff.go @@ -2179,6 +2179,17 @@ func qualifyEntityNameMode(entitySchema, entityName, targetSchema string, qualif return fmt.Sprintf("%s.%s", quotedSchema, quotedName) } +// qualifyColumnCommentTable returns the table name for use in COMMENT ON COLUMN +// statements. Like qualifyEntityNameMode, it omits the schema when the table is +// in the target schema — unless the table name itself matches the target schema, +// which would cause stripSchemaQualifications to strip the table qualifier. +func qualifyColumnCommentTable(tableSchema, tableName, targetSchema string, qualifySchema bool) string { + if !qualifySchema && tableSchema == targetSchema && strings.EqualFold(tableName, targetSchema) { + return fmt.Sprintf("%s.%s", ir.QuoteIdentifier(tableSchema), ir.QuoteIdentifier(tableName)) + } + return qualifyEntityNameMode(tableSchema, tableName, targetSchema, qualifySchema) +} + // quoteString properly quotes a string for SQL, handling single quotes func quoteString(s string) string { // Escape single quotes by doubling them diff --git a/internal/diff/table.go b/internal/diff/table.go index 8f560897..b85c24ee 100644 --- a/internal/diff/table.go +++ b/internal/diff/table.go @@ -456,9 +456,7 @@ func generateCreateTablesSQL( // Add column comments for _, column := range table.Columns { if column.Comment != "" { - // Always schema-qualify so stripSchemaQualifications can safely - // remove the schema prefix without mangling the table.column part. - tableName := fmt.Sprintf("%s.%s", ir.QuoteIdentifier(table.Schema), ir.QuoteIdentifier(table.Name)) + tableName := qualifyColumnCommentTable(table.Schema, table.Name, targetSchema, collector.qualifySchema) sql := fmt.Sprintf("COMMENT ON COLUMN %s.%s IS %s;", tableName, ir.QuoteIdentifier(column.Name), quoteString(column.Comment)) // Create context for this statement @@ -1136,7 +1134,7 @@ func (td *tableDiff) generateAlterTableStatements(targetSchema string, collector // Add comments for new columns for _, column := range td.AddedColumns { if column.Comment != "" { - tableName := fmt.Sprintf("%s.%s", ir.QuoteIdentifier(td.Table.Schema), ir.QuoteIdentifier(td.Table.Name)) + tableName := qualifyColumnCommentTable(td.Table.Schema, td.Table.Name, targetSchema, false) sql := fmt.Sprintf("COMMENT ON COLUMN %s.%s IS %s;", tableName, ir.QuoteIdentifier(column.Name), quoteString(column.Comment)) context := &diffContext{ @@ -1605,7 +1603,7 @@ func (td *tableDiff) generateAlterTableStatements(targetSchema string, collector // Handle column comment changes for _, colDiff := range td.ModifiedColumns { if colDiff.Old.Comment != colDiff.New.Comment { - tableName := fmt.Sprintf("%s.%s", ir.QuoteIdentifier(td.Table.Schema), ir.QuoteIdentifier(td.Table.Name)) + tableName := qualifyColumnCommentTable(td.Table.Schema, td.Table.Name, targetSchema, false) var sql string if colDiff.New.Comment == "" { sql = fmt.Sprintf("COMMENT ON COLUMN %s.%s IS NULL;", tableName, ir.QuoteIdentifier(colDiff.New.Name)) diff --git a/testdata/diff/comment/add_column_comments/diff.sql b/testdata/diff/comment/add_column_comments/diff.sql index d48b36e8..0a8c87f5 100644 --- a/testdata/diff/comment/add_column_comments/diff.sql +++ b/testdata/diff/comment/add_column_comments/diff.sql @@ -1,7 +1,7 @@ -COMMENT ON COLUMN public.products.id IS 'Unique product identifier'; +COMMENT ON COLUMN products.id IS 'Unique product identifier'; -COMMENT ON COLUMN public.products.name IS 'Product display name'; +COMMENT ON COLUMN products.name IS 'Product display name'; -COMMENT ON COLUMN public.products.price IS 'Product price in USD'; +COMMENT ON COLUMN products.price IS 'Product price in USD'; -COMMENT ON COLUMN public.products.created_at IS 'Timestamp when product was added'; +COMMENT ON COLUMN products.created_at IS 'Timestamp when product was added'; diff --git a/testdata/diff/comment/add_column_comments/plan.json b/testdata/diff/comment/add_column_comments/plan.json index 423e801c..355d3789 100644 --- a/testdata/diff/comment/add_column_comments/plan.json +++ b/testdata/diff/comment/add_column_comments/plan.json @@ -9,25 +9,25 @@ { "steps": [ { - "sql": "COMMENT ON COLUMN public.products.id IS 'Unique product identifier';", + "sql": "COMMENT ON COLUMN products.id IS 'Unique product identifier';", "type": "table.column.comment", "operation": "alter", "path": "public.products.id" }, { - "sql": "COMMENT ON COLUMN public.products.name IS 'Product display name';", + "sql": "COMMENT ON COLUMN products.name IS 'Product display name';", "type": "table.column.comment", "operation": "alter", "path": "public.products.name" }, { - "sql": "COMMENT ON COLUMN public.products.price IS 'Product price in USD';", + "sql": "COMMENT ON COLUMN products.price IS 'Product price in USD';", "type": "table.column.comment", "operation": "alter", "path": "public.products.price" }, { - "sql": "COMMENT ON COLUMN public.products.created_at IS 'Timestamp when product was added';", + "sql": "COMMENT ON COLUMN products.created_at IS 'Timestamp when product was added';", "type": "table.column.comment", "operation": "alter", "path": "public.products.created_at" diff --git a/testdata/diff/comment/add_column_comments/plan.sql b/testdata/diff/comment/add_column_comments/plan.sql index d48b36e8..0a8c87f5 100644 --- a/testdata/diff/comment/add_column_comments/plan.sql +++ b/testdata/diff/comment/add_column_comments/plan.sql @@ -1,7 +1,7 @@ -COMMENT ON COLUMN public.products.id IS 'Unique product identifier'; +COMMENT ON COLUMN products.id IS 'Unique product identifier'; -COMMENT ON COLUMN public.products.name IS 'Product display name'; +COMMENT ON COLUMN products.name IS 'Product display name'; -COMMENT ON COLUMN public.products.price IS 'Product price in USD'; +COMMENT ON COLUMN products.price IS 'Product price in USD'; -COMMENT ON COLUMN public.products.created_at IS 'Timestamp when product was added'; +COMMENT ON COLUMN products.created_at IS 'Timestamp when product was added'; diff --git a/testdata/diff/comment/add_column_comments/plan.txt b/testdata/diff/comment/add_column_comments/plan.txt index 3e4f5967..b61e65d0 100644 --- a/testdata/diff/comment/add_column_comments/plan.txt +++ b/testdata/diff/comment/add_column_comments/plan.txt @@ -13,10 +13,10 @@ Tables: DDL to be executed: -------------------------------------------------- -COMMENT ON COLUMN public.products.id IS 'Unique product identifier'; +COMMENT ON COLUMN products.id IS 'Unique product identifier'; -COMMENT ON COLUMN public.products.name IS 'Product display name'; +COMMENT ON COLUMN products.name IS 'Product display name'; -COMMENT ON COLUMN public.products.price IS 'Product price in USD'; +COMMENT ON COLUMN products.price IS 'Product price in USD'; -COMMENT ON COLUMN public.products.created_at IS 'Timestamp when product was added'; +COMMENT ON COLUMN products.created_at IS 'Timestamp when product was added'; diff --git a/testdata/diff/comment/column_comment_quoted_identifier/diff.sql b/testdata/diff/comment/column_comment_quoted_identifier/diff.sql index 800e5f97..a55753ec 100644 --- a/testdata/diff/comment/column_comment_quoted_identifier/diff.sql +++ b/testdata/diff/comment/column_comment_quoted_identifier/diff.sql @@ -1 +1 @@ -COMMENT ON COLUMN public.ex."ID" IS 'Primary identifier'; +COMMENT ON COLUMN ex."ID" IS 'Primary identifier'; diff --git a/testdata/diff/comment/column_comment_quoted_identifier/plan.json b/testdata/diff/comment/column_comment_quoted_identifier/plan.json index 237b6424..83187cd1 100644 --- a/testdata/diff/comment/column_comment_quoted_identifier/plan.json +++ b/testdata/diff/comment/column_comment_quoted_identifier/plan.json @@ -9,7 +9,7 @@ { "steps": [ { - "sql": "COMMENT ON COLUMN public.ex.\"ID\" IS 'Primary identifier';", + "sql": "COMMENT ON COLUMN ex.\"ID\" IS 'Primary identifier';", "type": "table.column.comment", "operation": "alter", "path": "public.ex.ID" diff --git a/testdata/diff/comment/column_comment_quoted_identifier/plan.sql b/testdata/diff/comment/column_comment_quoted_identifier/plan.sql index 800e5f97..a55753ec 100644 --- a/testdata/diff/comment/column_comment_quoted_identifier/plan.sql +++ b/testdata/diff/comment/column_comment_quoted_identifier/plan.sql @@ -1 +1 @@ -COMMENT ON COLUMN public.ex."ID" IS 'Primary identifier'; +COMMENT ON COLUMN ex."ID" IS 'Primary identifier'; diff --git a/testdata/diff/comment/column_comment_quoted_identifier/plan.txt b/testdata/diff/comment/column_comment_quoted_identifier/plan.txt index 4ea8bdb1..21265294 100644 --- a/testdata/diff/comment/column_comment_quoted_identifier/plan.txt +++ b/testdata/diff/comment/column_comment_quoted_identifier/plan.txt @@ -10,4 +10,4 @@ Tables: DDL to be executed: -------------------------------------------------- -COMMENT ON COLUMN public.ex."ID" IS 'Primary identifier'; +COMMENT ON COLUMN ex."ID" IS 'Primary identifier'; diff --git a/testdata/diff/comment/mixed_comments/diff.sql b/testdata/diff/comment/mixed_comments/diff.sql index a38ecb4c..9fdf7197 100644 --- a/testdata/diff/comment/mixed_comments/diff.sql +++ b/testdata/diff/comment/mixed_comments/diff.sql @@ -1,32 +1,32 @@ COMMENT ON TABLE categories IS 'Hierarchical category system for posts'; -COMMENT ON COLUMN public.categories.id IS 'Category unique identifier'; +COMMENT ON COLUMN categories.id IS 'Category unique identifier'; -COMMENT ON COLUMN public.categories.name IS 'Category display name'; +COMMENT ON COLUMN categories.name IS 'Category display name'; -COMMENT ON COLUMN public.categories.description IS 'Optional category description'; +COMMENT ON COLUMN categories.description IS 'Optional category description'; -COMMENT ON COLUMN public.categories.parent_id IS 'Parent category for hierarchical structure'; +COMMENT ON COLUMN categories.parent_id IS 'Parent category for hierarchical structure'; -COMMENT ON COLUMN public.categories.created_at IS 'Category creation timestamp'; +COMMENT ON COLUMN categories.created_at IS 'Category creation timestamp'; COMMENT ON INDEX idx_categories_parent IS 'Index for hierarchical category queries'; ALTER TABLE posts ADD COLUMN views integer DEFAULT 0; -COMMENT ON COLUMN public.posts.views IS 'Number of post views'; +COMMENT ON COLUMN posts.views IS 'Number of post views'; COMMENT ON TABLE posts IS 'Blog posts and articles'; -COMMENT ON COLUMN public.posts.id IS 'Unique post identifier'; +COMMENT ON COLUMN posts.id IS 'Unique post identifier'; -COMMENT ON COLUMN public.posts.title IS 'Post title, max 200 characters'; +COMMENT ON COLUMN posts.title IS 'Post title, max 200 characters'; -COMMENT ON COLUMN public.posts.content IS 'Post body in markdown format'; +COMMENT ON COLUMN posts.content IS 'Post body in markdown format'; -COMMENT ON COLUMN public.posts.author_id IS 'Foreign key to users table'; +COMMENT ON COLUMN posts.author_id IS 'Foreign key to users table'; -COMMENT ON COLUMN public.posts.published_at IS 'Publication timestamp, NULL for drafts'; +COMMENT ON COLUMN posts.published_at IS 'Publication timestamp, NULL for drafts'; COMMENT ON INDEX idx_posts_author IS 'Index for finding posts by author'; diff --git a/testdata/diff/comment/mixed_comments/plan.json b/testdata/diff/comment/mixed_comments/plan.json index db4520ac..8cbaeca3 100644 --- a/testdata/diff/comment/mixed_comments/plan.json +++ b/testdata/diff/comment/mixed_comments/plan.json @@ -15,31 +15,31 @@ "path": "public.categories" }, { - "sql": "COMMENT ON COLUMN public.categories.id IS 'Category unique identifier';", + "sql": "COMMENT ON COLUMN categories.id IS 'Category unique identifier';", "type": "table.column.comment", "operation": "alter", "path": "public.categories.id" }, { - "sql": "COMMENT ON COLUMN public.categories.name IS 'Category display name';", + "sql": "COMMENT ON COLUMN categories.name IS 'Category display name';", "type": "table.column.comment", "operation": "alter", "path": "public.categories.name" }, { - "sql": "COMMENT ON COLUMN public.categories.description IS 'Optional category description';", + "sql": "COMMENT ON COLUMN categories.description IS 'Optional category description';", "type": "table.column.comment", "operation": "alter", "path": "public.categories.description" }, { - "sql": "COMMENT ON COLUMN public.categories.parent_id IS 'Parent category for hierarchical structure';", + "sql": "COMMENT ON COLUMN categories.parent_id IS 'Parent category for hierarchical structure';", "type": "table.column.comment", "operation": "alter", "path": "public.categories.parent_id" }, { - "sql": "COMMENT ON COLUMN public.categories.created_at IS 'Category creation timestamp';", + "sql": "COMMENT ON COLUMN categories.created_at IS 'Category creation timestamp';", "type": "table.column.comment", "operation": "alter", "path": "public.categories.created_at" @@ -57,7 +57,7 @@ "path": "public.posts.views" }, { - "sql": "COMMENT ON COLUMN public.posts.views IS 'Number of post views';", + "sql": "COMMENT ON COLUMN posts.views IS 'Number of post views';", "type": "table.column.comment", "operation": "create", "path": "public.posts.views" @@ -69,31 +69,31 @@ "path": "public.posts" }, { - "sql": "COMMENT ON COLUMN public.posts.id IS 'Unique post identifier';", + "sql": "COMMENT ON COLUMN posts.id IS 'Unique post identifier';", "type": "table.column.comment", "operation": "alter", "path": "public.posts.id" }, { - "sql": "COMMENT ON COLUMN public.posts.title IS 'Post title, max 200 characters';", + "sql": "COMMENT ON COLUMN posts.title IS 'Post title, max 200 characters';", "type": "table.column.comment", "operation": "alter", "path": "public.posts.title" }, { - "sql": "COMMENT ON COLUMN public.posts.content IS 'Post body in markdown format';", + "sql": "COMMENT ON COLUMN posts.content IS 'Post body in markdown format';", "type": "table.column.comment", "operation": "alter", "path": "public.posts.content" }, { - "sql": "COMMENT ON COLUMN public.posts.author_id IS 'Foreign key to users table';", + "sql": "COMMENT ON COLUMN posts.author_id IS 'Foreign key to users table';", "type": "table.column.comment", "operation": "alter", "path": "public.posts.author_id" }, { - "sql": "COMMENT ON COLUMN public.posts.published_at IS 'Publication timestamp, NULL for drafts';", + "sql": "COMMENT ON COLUMN posts.published_at IS 'Publication timestamp, NULL for drafts';", "type": "table.column.comment", "operation": "alter", "path": "public.posts.published_at" diff --git a/testdata/diff/comment/mixed_comments/plan.sql b/testdata/diff/comment/mixed_comments/plan.sql index a38ecb4c..9fdf7197 100644 --- a/testdata/diff/comment/mixed_comments/plan.sql +++ b/testdata/diff/comment/mixed_comments/plan.sql @@ -1,32 +1,32 @@ COMMENT ON TABLE categories IS 'Hierarchical category system for posts'; -COMMENT ON COLUMN public.categories.id IS 'Category unique identifier'; +COMMENT ON COLUMN categories.id IS 'Category unique identifier'; -COMMENT ON COLUMN public.categories.name IS 'Category display name'; +COMMENT ON COLUMN categories.name IS 'Category display name'; -COMMENT ON COLUMN public.categories.description IS 'Optional category description'; +COMMENT ON COLUMN categories.description IS 'Optional category description'; -COMMENT ON COLUMN public.categories.parent_id IS 'Parent category for hierarchical structure'; +COMMENT ON COLUMN categories.parent_id IS 'Parent category for hierarchical structure'; -COMMENT ON COLUMN public.categories.created_at IS 'Category creation timestamp'; +COMMENT ON COLUMN categories.created_at IS 'Category creation timestamp'; COMMENT ON INDEX idx_categories_parent IS 'Index for hierarchical category queries'; ALTER TABLE posts ADD COLUMN views integer DEFAULT 0; -COMMENT ON COLUMN public.posts.views IS 'Number of post views'; +COMMENT ON COLUMN posts.views IS 'Number of post views'; COMMENT ON TABLE posts IS 'Blog posts and articles'; -COMMENT ON COLUMN public.posts.id IS 'Unique post identifier'; +COMMENT ON COLUMN posts.id IS 'Unique post identifier'; -COMMENT ON COLUMN public.posts.title IS 'Post title, max 200 characters'; +COMMENT ON COLUMN posts.title IS 'Post title, max 200 characters'; -COMMENT ON COLUMN public.posts.content IS 'Post body in markdown format'; +COMMENT ON COLUMN posts.content IS 'Post body in markdown format'; -COMMENT ON COLUMN public.posts.author_id IS 'Foreign key to users table'; +COMMENT ON COLUMN posts.author_id IS 'Foreign key to users table'; -COMMENT ON COLUMN public.posts.published_at IS 'Publication timestamp, NULL for drafts'; +COMMENT ON COLUMN posts.published_at IS 'Publication timestamp, NULL for drafts'; COMMENT ON INDEX idx_posts_author IS 'Index for finding posts by author'; diff --git a/testdata/diff/comment/mixed_comments/plan.txt b/testdata/diff/comment/mixed_comments/plan.txt index c519e02e..6ac14ba1 100644 --- a/testdata/diff/comment/mixed_comments/plan.txt +++ b/testdata/diff/comment/mixed_comments/plan.txt @@ -29,33 +29,33 @@ DDL to be executed: COMMENT ON TABLE categories IS 'Hierarchical category system for posts'; -COMMENT ON COLUMN public.categories.id IS 'Category unique identifier'; +COMMENT ON COLUMN categories.id IS 'Category unique identifier'; -COMMENT ON COLUMN public.categories.name IS 'Category display name'; +COMMENT ON COLUMN categories.name IS 'Category display name'; -COMMENT ON COLUMN public.categories.description IS 'Optional category description'; +COMMENT ON COLUMN categories.description IS 'Optional category description'; -COMMENT ON COLUMN public.categories.parent_id IS 'Parent category for hierarchical structure'; +COMMENT ON COLUMN categories.parent_id IS 'Parent category for hierarchical structure'; -COMMENT ON COLUMN public.categories.created_at IS 'Category creation timestamp'; +COMMENT ON COLUMN categories.created_at IS 'Category creation timestamp'; COMMENT ON INDEX idx_categories_parent IS 'Index for hierarchical category queries'; ALTER TABLE posts ADD COLUMN views integer DEFAULT 0; -COMMENT ON COLUMN public.posts.views IS 'Number of post views'; +COMMENT ON COLUMN posts.views IS 'Number of post views'; COMMENT ON TABLE posts IS 'Blog posts and articles'; -COMMENT ON COLUMN public.posts.id IS 'Unique post identifier'; +COMMENT ON COLUMN posts.id IS 'Unique post identifier'; -COMMENT ON COLUMN public.posts.title IS 'Post title, max 200 characters'; +COMMENT ON COLUMN posts.title IS 'Post title, max 200 characters'; -COMMENT ON COLUMN public.posts.content IS 'Post body in markdown format'; +COMMENT ON COLUMN posts.content IS 'Post body in markdown format'; -COMMENT ON COLUMN public.posts.author_id IS 'Foreign key to users table'; +COMMENT ON COLUMN posts.author_id IS 'Foreign key to users table'; -COMMENT ON COLUMN public.posts.published_at IS 'Publication timestamp, NULL for drafts'; +COMMENT ON COLUMN posts.published_at IS 'Publication timestamp, NULL for drafts'; COMMENT ON INDEX idx_posts_author IS 'Index for finding posts by author'; diff --git a/testdata/diff/create_table/add_table_like/diff.sql b/testdata/diff/create_table/add_table_like/diff.sql index e78a9750..1a41b787 100644 --- a/testdata/diff/create_table/add_table_like/diff.sql +++ b/testdata/diff/create_table/add_table_like/diff.sql @@ -15,6 +15,6 @@ CREATE TABLE IF NOT EXISTS users ( CONSTRAINT _template_timestamps_check CHECK (created_at <= updated_at) ); -COMMENT ON COLUMN public.users.created_at IS 'Record creation time'; +COMMENT ON COLUMN users.created_at IS 'Record creation time'; CREATE INDEX IF NOT EXISTS users_created_at_idx ON users (created_at); \ No newline at end of file diff --git a/testdata/diff/create_table/add_table_like/plan.json b/testdata/diff/create_table/add_table_like/plan.json index 4933bc12..dd33c472 100644 --- a/testdata/diff/create_table/add_table_like/plan.json +++ b/testdata/diff/create_table/add_table_like/plan.json @@ -21,7 +21,7 @@ "path": "public.users" }, { - "sql": "COMMENT ON COLUMN public.users.created_at IS 'Record creation time';", + "sql": "COMMENT ON COLUMN users.created_at IS 'Record creation time';", "type": "table.column.comment", "operation": "create", "path": "public.users.created_at" diff --git a/testdata/diff/create_table/add_table_like/plan.sql b/testdata/diff/create_table/add_table_like/plan.sql index 57563f3d..053c7fce 100644 --- a/testdata/diff/create_table/add_table_like/plan.sql +++ b/testdata/diff/create_table/add_table_like/plan.sql @@ -15,6 +15,6 @@ CREATE TABLE IF NOT EXISTS users ( CONSTRAINT _template_timestamps_check CHECK (created_at <= updated_at) ); -COMMENT ON COLUMN public.users.created_at IS 'Record creation time'; +COMMENT ON COLUMN users.created_at IS 'Record creation time'; CREATE INDEX IF NOT EXISTS users_created_at_idx ON users (created_at); diff --git a/testdata/diff/create_table/add_table_like/plan.txt b/testdata/diff/create_table/add_table_like/plan.txt index f2bcd485..86830933 100644 --- a/testdata/diff/create_table/add_table_like/plan.txt +++ b/testdata/diff/create_table/add_table_like/plan.txt @@ -29,6 +29,6 @@ CREATE TABLE IF NOT EXISTS users ( CONSTRAINT _template_timestamps_check CHECK (created_at <= updated_at) ); -COMMENT ON COLUMN public.users.created_at IS 'Record creation time'; +COMMENT ON COLUMN users.created_at IS 'Record creation time'; CREATE INDEX IF NOT EXISTS users_created_at_idx ON users (created_at);