compareSchemas
compareSchemas(
source,target,isPush):SchemaChange[]
Defined in: schema/ast/compare.ts:277
Compares two SchemaAST objects and returns structured changes. This enables semantic diffing instead of string comparison.
Parameters
Section titled “Parameters”source
Section titled “source”The “source of truth” schema (what we want to apply)
target
Section titled “target”The “target” schema (what currently exists)
isPush
Section titled “isPush”boolean = false
If true, source=code, target=database (pushing code to DB) If false, source=database, target=code (pulling DB to code)
Returns
Section titled “Returns”Array of schema changes
Example
Section titled “Example”const codeSchema = extractSchemaFromDefinables([User, Post]);const dbSchema = await introspectDatabase(db);
// Find what needs to change in DB to match codeconst changes = compareSchemas(codeSchema, dbSchema, true);
// Find what needs to change in code to match DBconst changes = compareSchemas(dbSchema, codeSchema, false);