Serialization
A build writes two files, beside each other. Which pair depends on the dialect the project declares.
- The primary output (the
-ofile,dist/schema.jsonby convention), one JSON document.dialectisclickhouseorpostgres.applyOrderlists the export names in the order the objects have to be created.objectsholds one entry per declared object, in that order: its export name (export), its type, its SQL name (sqlName), its parsed definition,dependsOn, and itsddl. References are written as export names and lineage asexport.column.- ClickHouse: the types are
ClickHouse::Database,::Table,::Viewand::MaterializedView, and the definition holds columns, engine, keys, TTL, settings, indexes, projections and constraints, and for a view itsselect,reads,toandlineage. - Postgres: the document also carries
postgresMajor, the major the project targets (sql.postgresMajor, else 18, the newest pinned). The types arePostgres::Schema,::Table,::Index,::View,::MaterializedView,::Sequence,::Enum,::Domainand::Extension. A table’s definition holds its columns, primary key, uniques, checks, foreign keys, exclusions and the rest of its clauses; a view’s itsquery,readsandlineage; an index’s its table, method and elements.dependsOnnames the objects and the columns the statement references.
- ClickHouse: the types are
clickhouse.sqlorpostgres.sql: every statement inapplyOrder, each ending in;, written byte for byte as declared, with a Postgres template’sCOMMENT ONstatements after itsCREATE.
The order follows the references: a table after its database or schema and the
types and sequences it uses, a view after the tables it reads, an index after
its table, a materialized view after its TO target. Ties go by export name,
so the output does not depend on the order files were found in. A reference
cycle fails the build and names the cycle.
chant sql diff, chant sql plan, the post-synth checks and the appliers
read the JSON document. Neither file carries chant’s ownership marker: the
applier adds it to each object’s comment when it creates the object (see
Applying to a ClickHouse Server and
Applying to a Postgres Server).