The entities from your EntityMap.
The last committed SchemaSnapshot (empty on first run).
{ up, down, full, isEmpty, nextSnapshot } where nextSnapshot
should be written to disk after the migration file is created.
const prev = loadSnapshot('./migrations/snapshot.json');
const result = generateMigrationsForContext(
Object.values({ todos: TodoEntity, users: UserEntity }),
prev
);
if (!result.isEmpty) {
fs.writeFileSync('migrations/20260423000000_init.ts', result.full);
writeSnapshot('./migrations/snapshot.json', result.nextSnapshot);
}
Generate a single combined migration (up + down) for a set of entities by diffing the current code-first schemas against a serialized snapshot stored in the repository — no live database connection required.
For each entity's table the function:
prevSnapshot): emitsCREATE TABLE.ALTER TABLEwhen changes exist.prevSnapshotbut not in entities): emitsDROP TABLEwith a best-effortCREATE TABLEin thedowndirection.up(and dropped after indown).