Skip to content
🚀 This documentation is for unreal-orm 1.0.0 alpha which requires SurrealDB 2.0 alpha SDK. For the stable version, see npm.

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.

SchemaAST

The “source of truth” schema (what we want to apply)

SchemaAST

The “target” schema (what currently exists)

boolean = false

If true, source=code, target=database (pushing code to DB) If false, source=database, target=code (pulling DB to code)

SchemaChange[]

Array of schema changes

const codeSchema = extractSchemaFromDefinables([User, Post]);
const dbSchema = await introspectDatabase(db);
// Find what needs to change in DB to match code
const changes = compareSchemas(codeSchema, dbSchema, true);
// Find what needs to change in code to match DB
const changes = compareSchemas(dbSchema, codeSchema, false);