Skip to content

feat: support COMMENT ON for all schema objects#278

Open
dilame wants to merge 1 commit intostripe:mainfrom
dilame:feat/comment-diffs
Open

feat: support COMMENT ON for all schema objects#278
dilame wants to merge 1 commit intostripe:mainfrom
dilame:feat/comment-diffs

Conversation

@dilame
Copy link
Copy Markdown

@dilame dilame commented Apr 28, 2026

What

Plan and apply COMMENT ON ... IS '...' (or IS NULL to clear) whenever a description is added, changed, or removed in the declarative schema.

Covered: schema, extension, table, column, type/enum, sequence, index, primary/unique constraint, check constraint, foreign key, function, procedure, trigger, view, materialized view, policy.

Why

COMMENT ON ... is part of the declarative schema (notably for tools like PostGraphile that consume comments as smart-tags), but plans currently silently drop them, forcing manual application alongside every migration.

How

  • internal/queries/queries.sql: extended each existing Get* query to fetch obj_description / col_description.
  • internal/schema/schema.go: added Description string to every commentable schema struct.
  • pkg/diff/comment_sql_generator.go: shared helpers (commentDDLForAdd, commentDDLForAlter, commentTarget*).
  • Per-object SQL generators emit COMMENT ON ... after CREATE and on description-only diffs (without recreating the underlying object — important for views, functions, procedures, etc.).
  • internal/migration_acceptance_tests/comment_cases_test.go: 31 cases — CREATE-with-comment, add, change, and remove for each object kind.

No new flags; comment diffing is always-on. The behavior of all pre-existing tests is unchanged (snapshot hashes were re-computed where the test fixtures expected an empty description on objects that PG itself comments by default — e.g. the public schema, pg_stat_statements, pg_trgm).

Plumb pg_description through the introspection path and emit
`COMMENT ON <kind> <name> IS '...'` (or `IS NULL` to clear) whenever
the description on a schema object is added, changed, or removed.

Covered objects: schema, extension, table, column, enum/type,
sequence, index, primary/unique constraint (via index), check
constraint, foreign key, function, procedure, trigger, view,
materialized view, policy.

Acceptance coverage: internal/migration_acceptance_tests/comment_cases_test.go.
@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented Apr 28, 2026

CLA assistant check
All committers have signed the CLA.

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.

1 participant