Repository navigation
feat(pg): support composite types in schema sync and SDL dump - #20911
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 313736b31d
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1315b90520
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d34560c77
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 54a49ab681
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 389926a710
ℹ️ 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".
PostgreSQL composite types (CREATE TYPE ... AS) were not modeled in SchemaMetadata, so the SDL flow reconstructed source schemas without their CREATE TYPE statements and omni's LoadSDL rejected the unresolved references (SQLSTATE 42704), failing on the database's own synced schema. Fixes the loader half of #20434. - Add CompositeTypeMetadata / CompositeTypeAttribute to the store and v1 protos (attributes carry type, collation, and comment; attribute types are always schema-qualified for determinism) - Sync standalone composite types (pg_class relkind 'c') with extension-owned types marked skip_dump, mirroring enums - Emit composite types in all four definition paths, ordered enums first and composites topologically so referenced composites precede their dependents - Correct the stale action/README.md declarative-mode limitations list - Record the per-concept type-metadata decision in docs/adr/0001 and the Composite Type term in CONTEXT.md Sync Schema diff support and the walk-through/query-span catalog loaders follow in separate PRs. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Order types.sql before table files in multi-file output so naive in-order consumption sees types before the tables using them - Extract collectCompositeTypes/writeCompositeTypesSection shared by the three single-buffer dump paths (quality gate duplication) - Build the composite type sync query once at package init (S2077) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Filter system schemas on the Go side via pgparser.IsSystemSchema instead of interpolating the schema list into the SQL text. relkind = 'c' already keeps system-schema rows near zero, so the SQL-side filter was only a minor optimization. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A bare collation name cannot resolve when the collation lives outside pg_catalog (the dump header pins search_path) and can resolve to the wrong same-named collation in another schema. Store the collation as an emit-ready identifier reference instead — quoted as needed and schema-qualified outside pg_catalog (e.g. `"C"`, `locale.en_us`) — and emit it verbatim after COLLATE. The field format is settled now, before the first release ships it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Composite type attributes and table columns may use extension-provided types, so extensions.sql must precede the per-schema files for in-order consumption, matching the single-file emission order. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…tput Extensions may install into non-public schemas (CREATE EXTENSION ... WITH SCHEMA), so schema files must come first. Final in-order layout matches the single-file emission: schemas, extensions, types, sequences, tables. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
b512e2f to
8d0bd52
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d0bd52c4b
ℹ️ 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".
The flag is sync-computed bookkeeping (extension ownership from pg_depend), not user-configurable, and nothing consumes it over the API. Keep it in the store proto where dump and diff logic lives. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 87828c0144
ℹ️ 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".




What
Adds PostgreSQL composite type (
CREATE TYPE ... AS) support to schema sync and all schema definition dump paths. Fixes the loader half of #20434 (Linear BYT-9668).Why
SchemaMetadatamodeled enum types but not composite types, soSDLMigrationreconstructed source schemas that reference composite types without ever creating them. omni's dependency-awareLoadSDLthen rejected the dump —ERROR: type "..." does not exist (SQLSTATE 42704)— on the database's own synced schema, which users cannot fix by editing their files.How
CompositeTypeMetadata/CompositeTypeAttributemessages (store + v1),composite_typesfield 17 onSchemaMetadata. Additive only; attributes carry type, collation, and comment. Per-concept message design is recorded indocs/adr/0001-per-concept-type-metadata.md.getCompositeTypesin the PG driver — standalone composites only (pg_class.relkind = 'c', table/view row types excluded), dropped attributes excluded, extension-owned types markedskip_dump, zero-attribute types supported. Attribute types are rendered byformat_typeand always schema-qualified for user-defined types, so stored strings are deterministic regardless ofsearch_path.GetDatabaseDefinition,GetSchemaDefinition, SDL format, multi-file), after enums and before sequences/tables, topologically sorted so referenced composites precede dependents (PostgreSQL forbids containment cycles, so the sort cannot loop). Type and attribute comments emitted.action/README.md— the parser already supported these statements; the gap was metadata fidelity.Known limitation (deliberate): a composite attribute typed with a table/view row type is not reordered relative to tables in plain dumps — that requires
pg_depend-grade dependency data (cf.pg_dump_sort.c). The SDL flow is unaffected sinceLoadSDLresolves dependencies itself.Sync Schema diff generation and the walk-through/query-span catalog loaders follow in separate PRs.
Testing
TestSyncCompositeTypesWithTestcontainer— pins exact synced metadata (qualification, collation, comments, empty types, row-type exclusion) against real PostgreSQL.TestGetDatabaseDefinitionWithTestcontainer/composite_types— full round-trip: DDL → sync → dump → replay on a fresh database → sync → metadata equality. Includes nested/cross-schema/array/empty composites and adversarial names (dependent sorts alphabetically before its dependency).TestGetDatabaseDefinitionSDLFormat_CompositeTypes/TestGetMultiFileDatabaseDefinition_CompositeTypes— emission order, skip_dump exclusion, and loadability throughDiffSDLMigration(the exact path that failed in Can't use SDL or Sync Schema due to "does not exist" errors #20434).db/pg,schema/pg,api/v1all pass.🤖 Generated with Claude Code