Skip to content

Rebuild as a dialect-independent schema representation - #7

Merged
nbenn merged 1 commit into
mainfrom
v0-schema-ir
Aug 28, 2026
Merged

Rebuild as a dialect-independent schema representation#7
nbenn merged 1 commit into
mainfrom
v0-schema-ir

Conversation

@nbenn

@nbenn nbenn commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replaces the R7-era proof of concept with an S7 representation of a relational schema — tables, columns, types, constraints and indexes — together with the protocol that dialect packages implement. The old Remotes: RConsortium/OOP-WG pin resolves to nothing now that R7 has become S7, so the package could not be installed at all.
  • Dialects dispatch on a dialect object rather than on a connection class. This package therefore depends on no driver package, and the whole suite runs with no database.
  • Rendering a schema is not rendering each table in turn: foreign keys can form cycles, so tables are emitted in dependency order and any foreign key closing a cycle is hoisted into a trailing ALTER TABLE. Engines with no ADD CONSTRAINT opt out through sqlr_defers_constraints().
  • Comparison is structural — constraints and indexes are matched on what they constrain rather than on their order or their names — so a schema authored here compares equal to the same schema read back out of a database that picked its own constraint names.
  • The PostgreSQL and SQLite dialects live in nbenn/sqlr.postgres and nbenn/sqlr.sqlite, where a render/execute/reflect round trip is asserted against a real engine.

There is no issue to close — this came out of a design discussion, so no Fixes trailer. Say the word if you would rather it hung off one.

Replaces the R7-era proof of concept with an S7 representation of a
relational schema -- tables, columns, types, constraints and indexes --
together with the protocol that dialect packages implement.

Rendering a schema is not rendering each table in turn. Foreign keys can
form cycles, so tables are emitted in dependency order and any foreign
key closing a cycle is hoisted into a trailing ALTER TABLE. Engines
without ADD CONSTRAINT opt out through sqlr_defers_constraints().

Comparison is structural: constraints and indexes are matched on what
they constrain rather than on their order or their names, so a schema
authored here compares equal to the same schema read back out of a
database that chose its own constraint names.

Dialects dispatch on a dialect object rather than on a connection, which
keeps this package free of database dependencies and lets the whole
suite run with no server.
@nbenn
nbenn marked this pull request as ready for review August 28, 2026 15:19
@nbenn
nbenn merged commit fc94c41 into main Aug 28, 2026
5 checks passed
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