Repository navigation
Conversation
Task file for replacing @sqlfu/pg's hand-rolled pg_catalog renderer with the vendored migra, so materializeSchemaSql/extractSchemaFromClient round-trip real Postgres schemas. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
commit: |
materializeSchemaSql/extractSchemaFromClient output, diffed against the original schema in both directions, should be empty. Fails today for serial, identity, enums, domains, generated columns, functions, triggers, matviews, extensions and non-public schemas. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
mmkal
added a commit
that referenced
this pull request
Oct 29, 2026
7c7e176 meant to fold tasks/complete/2026-10-29-pg-lossless-schema.md into the shared task's "Schema renderer" section but only deleted it. This restores that spec (condensed), ticks the section, points tasks/pg.md at #159 instead of the closed #161, and moves the task to complete now that all three sections are done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #156 (
pg-docs), because it edits that PR's "Known gaps" table.draft,checkandgeneratere-read Postgres schemas as SQL text, then diff that text. The text came from a hand-rolledpg_catalogrenderer that only knewpublictables, columns, constraints, indexes and views. Everything else was lost, so most real schemas broke:serialmadegeneratefail, identity columns came back in every draft, enums and domains didn't replay.Now the text is migra's diff from an empty database to yours (what pgkit's migrator does for
definitions.sql).diffSchemaalready uses the same migra, so whatever it can diff, the renderer can render.Round-trips after this PR (
materializeSchemaSql, thendiffSchemaboth ways, empty):serial/bigserial, identity, enums, domains (incl. over enums), stored generated columns, functions, triggers, materialized views, extensions, non-publicschemas, column collations. Plus 30-odd shapes probed by hand (partitions, RLS, inheritance, exclusion constraints,setoffunctions, ...).Rendered schema, before / after
Before (no enum, no sequence, constraint names dropped):
After (same style as Postgres drafts):
This is what the UI's live-schema pane shows now.
Still broken
migra creates every function and composite type after the tables. So a table whose default, check or generated column calls a user function, or that has a composite-type column, fails, in drafts too. Two
test.failscases pin it. It's a migra draft-ordering change that reshuffles fixture output, so it's left for its own PR (listed intasks/pg.md).Also listed in the guide: custom ICU collations lose
locale/deterministic; comments and grants are never drafted.packages/pg/src/impl/schema.ts:renderCanonicalSchema+ itspg_catalogqueries replaced byrenderSchema(migra fromPostgreSQL.empty()to the inspected db)omitTablesin the same fileexcludedTables(e.g.sqlfu_migrations) drops the table plus its indexes, constraints, triggers, policies and owned sequences from the inspector.publicschema andplpgsqlextensioncreate schema if not exists "public"was noise in the UI pane.vendor/migra/migra.ts,changes.ts: create new domains before tablestype "email" does not exist). Modified domains keep the old drop-then-create spot.vendor/schemainspect/pg/obj.ts:create domainends with;vendor/schemainspect/queries.ts: enums query usestyptype = 'e'typcategory = 'E'also matched domains over enums, so they were created twice.vendor/schemainspect/inspected.ts: collation inColumnInfo.creation_clausecreate tabledroppedcollate "C"; onlyadd columnkept it.packages/pg/test/schema-round-trip.test.tsextractSchemaFromClienton a live db andexcludedTables.docs/guides/postgres.md,guides/pgkit.md,packages/sqlfu/README.mduuidortextids for now" and the pgkit "schema coverage" caveat.tasks/pg.md,tasks/complete/2026-10-29-pg-lossless-schema.mdTested:
@sqlfu/pgtypecheck + full suite (postgres:16 frompackages/pg/test/docker-compose.yml), andpackages/ui/test/pg-studio.spec.ts(3/3).Session:
7f20d0b1-4a1e-4bfc-9594-63bff2958ec5🤖 Generated with Claude Code