Repository: ariga/atlas (Go)

Issue:
Atlas Schema Diff: DDL Generation for Comments on Tables
# Expected Behavior
When running the below style of command I would expect that a given comment DDL would be able to run within any sql client with proper formatting. The below command ideally would produce something below the command.

```bash
atlas schema diff \
        --env "prod" \
        --var "destructive=false" \
        --to "file://db.hcl" \
        --from "postgres://<user>:<pwd>@<host>:5432/<database>?sslmode=disable" \
        --format '{{ sql . "  " }}' \
        | 2>&1 >  t.sql
```

```sql
-- Set comment to column: "column" on table: "table"
COMMENT ON COLUMN "schema"."table"."column" IS '';
```

# Actual Behavior
Running the above produces an output for comment on solums where there is a space in between the table and the column like the below.

```sql
-- Set comment to column: "column" on table: "table"
COMMENT ON COLUMN "schema"."table". "column" IS '';
```

# Steps to Reproduce the Problem
Run the below where the diff in between the two is a change to the comment column.
```bash
atlas schema diff \
        --env "prod" \
        --var "destructive=false" \
        --to "file://db.hcl" \
        --from "postgres://<user>:<pwd>@<host>:5432/<database>?sslmode=disable" \
        --format '{{ sql . "  " }}' \
        | 2>&1 >  t.sql
```

# Specifications
Atlas
atlas version v0.23.1-ad76976-canary
https://github.com/ariga/atlas/releases/latest



Discussion:

Patch:
diff --git a/sql/postgres/migrate.go b/sql/postgres/migrate.go
index 1948958ee39..fe8b5a65e30 100644
--- a/sql/postgres/migrate.go
+++ b/sql/postgres/migrate.go
@@ -851,9 +851,8 @@ func (s *state) tableComment(src schema.Change, t *schema.Table, to, from string
 }
 
 func (s *state) columnComment(src schema.Change, t *schema.Table, c *schema.Column, to, from string) *migrate.Change {
-	b := s.Build("COMMENT ON COLUMN").Table(t)
-	b.WriteByte('.')
-	b.Ident(c.Name).P("IS")
+	b := s.Build("COMMENT ON COLUMN").TableResource(t, c)
+	b.P("IS")
 	return &migrate.Change{
 		Cmd:     b.Clone().P(quote(to)).String(),
 		Source:  src,


Test patch:
diff --git a/sql/postgres/migrate_test.go b/sql/postgres/migrate_test.go
index 7ba9db380ee..1f5d9df9e3e 100644
--- a/sql/postgres/migrate_test.go
+++ b/sql/postgres/migrate_test.go
@@ -856,12 +856,12 @@ func TestPlanChanges(t *testing.T) {
 						Reverse: `DROP INDEX "nulls_not_distinct"`,
 					},
 					{
-						Cmd:     `COMMENT ON COLUMN "users" ."name" IS 'foo'`,
-						Reverse: `COMMENT ON COLUMN "users" ."name" IS ''`,
+						Cmd:     `COMMENT ON COLUMN "users"."name" IS 'foo'`,
+						Reverse: `COMMENT ON COLUMN "users"."name" IS ''`,
 					},
 					{
-						Cmd:     `COMMENT ON COLUMN "users" ."last" IS 'bar'`,
-						Reverse: `COMMENT ON COLUMN "users" ."last" IS ''`,
+						Cmd:     `COMMENT ON COLUMN "users"."last" IS 'bar'`,
+						Reverse: `COMMENT ON COLUMN "users"."last" IS ''`,
 					},
 					{
 						Cmd:     `COMMENT ON INDEX "id_key" IS 'comment'`,
@@ -903,8 +903,8 @@ func TestPlanChanges(t *testing.T) {
 						Reverse: `ALTER TABLE "users" ALTER COLUMN "id" SET GENERATED BY DEFAULT SET START WITH 1 SET INCREMENT BY 1 RESTART, ADD COLUMN "name" character varying NOT NULL`,
 					},
 					{
-						Cmd:     `COMMENT ON COLUMN "users" ."id" IS ''`,
-						Reverse: `COMMENT ON COLUMN "users" ."id" IS 'comment'`,
+						Cmd:     `COMMENT ON COLUMN "users"."id" IS ''`,
+						Reverse: `COMMENT ON COLUMN "users"."id" IS 'comment'`,
 					},
 				},
 			},
@@ -1293,7 +1293,7 @@ func TestPlanChanges(t *testing.T) {
 				Transactional: true,
 				Changes: []*migrate.Change{
 					{Cmd: `ALTER TYPE "public"."state" ADD VALUE 'unknown'`},
-					{Cmd: `COMMENT ON COLUMN "public"."users" ."state" IS ''`, Reverse: `COMMENT ON COLUMN "public"."users" ."state" IS 'foo'`},
+					{Cmd: `COMMENT ON COLUMN "public"."users"."state" IS ''`, Reverse: `COMMENT ON COLUMN "public"."users"."state" IS 'foo'`},
 				},
 			},
 		},
@@ -1323,7 +1323,7 @@ func TestPlanChanges(t *testing.T) {
 				Reversible:    true,
 				Transactional: true,
 				Changes: []*migrate.Change{
-					{Cmd: `COMMENT ON COLUMN "users" ."state" IS 'foo'`, Reverse: `COMMENT ON COLUMN "users" ."state" IS 'bar'`},
+					{Cmd: `COMMENT ON COLUMN "users"."state" IS 'foo'`, Reverse: `COMMENT ON COLUMN "users"."state" IS 'bar'`},
 				},
 			},
 		},