feat(pg): generate Sync Schema migration DDL for composite types by h3n4l · Pull Request #20912 · bytebase/bytebase · GitHub
Skip to content

feat(pg): generate Sync Schema migration DDL for composite types - #20912

Merged
h3n4l merged 1 commit into
mainfrom
claude/byt-9668-pr2-sync-schema
Jul 15, 2026
Merged

h3n4l merged 1 commit into
mainfrom
claude/byt-9668-pr2-sync-schema

Conversation

@h3n4l

@h3n4l h3n4l commented Jul 15, 2026

Copy link
Copy Markdown
Member

What

Adds composite type support to the metadata differ and the PostgreSQL metadata-migration writer, giving Sync Schema parity with the SDL flow. Second PR of the BYT-9668 chain, stacked on #20911.

How

  • CompositeTypeDiff in the shared differ: create/drop, and alter when attributes (order-sensitive), collations, or comments change. FilterPostgresArchiveSchema filters the new changes like every other kind.
  • Migration DDL: CREATE TYPE ... AS in dependency order after enums; attribute changes as real ALTER TYPE ADD/DROP ATTRIBUTE and ALTER ATTRIBUTE ... TYPE statements (reviewable in the issue; PostgreSQL surfaces the in-use restriction at execution); attribute reordering — including middle insertion, which ADD ATTRIBUTE cannot express — emits a warning comment, mirroring the enum value-removal precedent.
  • Deferred drop phase: DROP TYPE must run after its last reference is released, and a column retype releases references only in the alter phase. computeDeferredDrops resolves this with a fixpoint — retype-released composites seed a pool; dropped schemas containing pooled-referenced types join the deferred set and contribute their composites; dropped enums referenced by any pooled composite defer too. The deferred phase then drops all deferred composites in one global reverse-dependency pass (correct even for cyclic cross-schema references), then deferred enums, then DROP SCHEMA statements.
  • Schema drops now include their composite types (previously DROP SCHEMA could run on a non-empty schema).

Testing

Sixteen focused tests covering create/drop/alter ordering, dependency and reverse-dependency ordering, enum-drop interaction, retype deferral, schema-drop deferral, cross-schema and cyclic deferred references, middle-insertion warnings, comment changes, archive-schema filtering, and skip_dump handling. ALTER TYPE ... ADD/ALTER ATTRIBUTE ... COLLATE syntax verified against PostgreSQL 17. Full schema/pg suite and lint green.

🤖 Generated with Claude Code

@h3n4l
h3n4l requested a review from a team as a code owner July 15, 2026 04:33
@cla-bot cla-bot Bot added the cla-signed label Jul 15, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 235d397d37

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread backend/plugin/schema/pg/metadata_migration.go Outdated
Comment thread backend/plugin/schema/pg/metadata_migration.go
@h3n4l
h3n4l force-pushed the claude/byt-9668-cf7383 branch from b512e2f to 8d0bd52 Compare July 15, 2026 07:12
@h3n4l
h3n4l force-pushed the claude/byt-9668-pr2-sync-schema branch from 235d397 to 38523ac Compare July 15, 2026 07:12

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38523acc21

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread backend/plugin/schema/pg/metadata_migration.go Outdated
Comment thread backend/plugin/schema/pg/metadata_migration.go Outdated
@h3n4l
h3n4l force-pushed the claude/byt-9668-pr2-sync-schema branch from 38523ac to 5943bc8 Compare July 15, 2026 07:20

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5943bc8471

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread backend/plugin/schema/pg/metadata_migration.go Outdated
Comment thread backend/plugin/schema/pg/metadata_migration.go Outdated
Comment thread backend/plugin/schema/pg/metadata_migration.go Outdated
@h3n4l
h3n4l force-pushed the claude/byt-9668-pr2-sync-schema branch from 5943bc8 to 050a01a Compare July 15, 2026 07:30
@h3n4l
h3n4l force-pushed the claude/byt-9668-pr2-sync-schema branch from 050a01a to 54614dc Compare July 15, 2026 08:33

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54614dc31c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread backend/plugin/schema/pg/metadata_migration.go
Comment thread backend/plugin/schema/pg/metadata_migration.go Outdated
Comment thread backend/plugin/schema/pg/metadata_migration.go Outdated
@h3n4l
h3n4l force-pushed the claude/byt-9668-pr2-sync-schema branch from 54614dc to 4950fe9 Compare July 15, 2026 08:51
Base automatically changed from claude/byt-9668-cf7383 to main July 15, 2026 08:56
@h3n4l
h3n4l force-pushed the claude/byt-9668-pr2-sync-schema branch from 4950fe9 to ef9f2aa Compare July 15, 2026 08:58

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ef9f2aad02

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread backend/plugin/schema/pg/metadata_migration.go
Comment thread backend/plugin/schema/pg/metadata_migration.go Outdated
Comment thread backend/plugin/schema/pg/metadata_migration.go Outdated
@h3n4l
h3n4l force-pushed the claude/byt-9668-pr2-sync-schema branch 2 times, most recently from 73887aa to 7c495b9 Compare July 15, 2026 09:13

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c495b9d4d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread backend/plugin/schema/pg/metadata_migration.go
Comment thread backend/plugin/schema/pg/metadata_migration.go
Comment thread backend/plugin/schema/pg/metadata_migration.go
@h3n4l
h3n4l force-pushed the claude/byt-9668-pr2-sync-schema branch from 7c495b9 to e1da0d9 Compare July 15, 2026 09:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1da0d99a5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread backend/plugin/schema/pg/metadata_migration.go
Comment thread backend/plugin/schema/pg/metadata_migration.go
Comment thread backend/plugin/schema/pg/metadata_migration.go Outdated
Comment thread backend/plugin/schema/pg/metadata_migration.go
Comment thread backend/plugin/schema/pg/metadata_migration.go
Adds composite type support to the metadata differ and the PostgreSQL
metadata-migration writer, giving Sync Schema parity with the SDL flow.

- CompositeTypeDiff in the shared differ: create/drop, and alter when
  attributes (order-sensitive), collations, or comments change
- Migration DDL: CREATE TYPE ... AS in dependency order after enums;
  DROP TYPE in reverse dependency order before enum drops; attribute
  changes as real ALTER TYPE ADD/DROP ATTRIBUTE and ALTER ATTRIBUTE
  ... TYPE statements (reviewable, and PostgreSQL surfaces the in-use
  restriction at execution); attribute reordering has no DDL and emits
  a warning comment, mirroring the enum value-removal precedent
- Type and attribute comment changes emit COMMENT ON TYPE / COLUMN

DDL syntax for ADD/ALTER ATTRIBUTE with COLLATE verified against
PostgreSQL 17.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@h3n4l
h3n4l force-pushed the claude/byt-9668-pr2-sync-schema branch from e1da0d9 to 539dd1b Compare July 15, 2026 09:46
@sonarqubecloud

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 539dd1bec2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread backend/plugin/schema/pg/metadata_migration.go
@h3n4l
h3n4l enabled auto-merge (squash) July 15, 2026 10:03
@h3n4l
h3n4l merged commit f96079f into main Jul 15, 2026
15 checks passed
@h3n4l
h3n4l deleted the claude/byt-9668-pr2-sync-schema branch July 15, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants