testing/schema_parity.ts

Cross-impl schema parity — structural diff + assertion over two SchemaSnapshots captured via query_schema_snapshot.

Two live impls (TS fuz_app vs Rust spine) are each other's parity reference. After both bootstrap, snapshot each, diff, fail loudly on drift. The diff entries name the specific divergence (column type, missing index, schema_version row absent on one side) so the error message points at the source.

Consumer pattern (in zzz's integration runner or fuz_app's own cross-backend tests):

const snapshot_a = await query_schema_snapshot(db_after_deno_bootstrap); const snapshot_b = await query_schema_snapshot(db_after_rust_bootstrap); assert_schema_snapshots_equal(snapshot_a, snapshot_b, {a: 'deno', b: 'rust'});

Non-coverage — drift the gate does not detect:

- enum types (CREATE TYPE ... AS ENUM) - regular triggers (pg_trigger); CONSTRAINT TRIGGER is captured via pg_constraint, but standalone CREATE TRIGGER is not - views, materialized views, functions, procedures - table storage parameters (fillfactor, tablespace, autovacuum settings) - column physical order — the snapshot keys columns by name, so two impls with the same columns in different declaration order compare equal (functional parity is preserved; SELECT * ordering is not) - COMMENT ON ... - the schema_version table's own structure (only its rows are captured) - permissions / GRANTs

None of these are used by the current fuz_app auth schema. Extend query_schema_snapshot + SchemaDiff if a consumer's schema reaches for them; omitting them today keeps the diff surface focused on what fuz_app actually emits.

Declarations
#

5 declarations

view source

assert_schema_snapshots_equal
#

testing/schema_parity.ts view source

(a: SchemaSnapshot, b: SchemaSnapshot, labels?: SchemaDiffLabels): void

Throw if the two snapshots disagree. The error message names the impls (via labels) and lists every diff, so the failure is self-diagnosing.

Consumers wire this after bootstrapping each impl against an isolated DB:

await drop_recreate_db('zzz_test'); await spawn_backend(deno_config); const snapshot_deno = await query_schema_snapshot(db, {}); await drop_recreate_db('zzz_test'); await spawn_backend(rust_config); const snapshot_rust = await query_schema_snapshot(db, {}); assert_schema_snapshots_equal(snapshot_deno, snapshot_rust, {a: 'deno', b: 'rust'});

a

b

labels

default {}

returns

void

diff_schema_snapshots
#

testing/schema_parity.ts view source

(a: SchemaSnapshot, b: SchemaSnapshot): SchemaDiff[]

Structural diff between two snapshots — empty array means parity holds.

Order of diffs is deterministic: schema_version first, then tables in sorted order (with column/index/constraint sub-diffs grouped per table), then sequences. Consumers can rely on this for stable diff output.

a

b

returns

SchemaDiff[]

format_schema_diffs
#

testing/schema_parity.ts view source

(diffs: readonly SchemaDiff[], labels?: SchemaDiffLabels): string

Render a diff list as a human-readable multi-line string. Empty diffs produce an empty string.

diffs

type readonly SchemaDiff[]

labels

default {}

returns

string

SchemaDiff
#

SchemaDiffLabels
#

Depends on
#