schema-migrate-lite
v0.1.0
Published
Versioning and migration utility for JSON-driven configs — define stepwise migrations and run a config forward to the latest version.
Maintainers
Readme
schema-migrate-lite
Versioning and migration utility for JSON-driven configs — define stepwise migrations and run a config forward to the latest (or any target) version. Zero dependencies.
Install
npm install schema-migrate-liteQuick start
import { MigrationRunner } from 'schema-migrate-lite';
const runner = new MigrationRunner([
{ from: 1, to: 2, migrate: (c) => ({ ...c, fullName: c.name, name: undefined }) },
{ from: 2, to: 3, migrate: (c) => ({ ...c, theme: 'default' }) },
]);
const upgraded = runner.migrate(storedConfig); // walks 1 -> 2 -> 3 automaticallyWhy stepwise migrations instead of one big transform
A single "convert any old version to the latest" function grows unreadable fast and has to be rewritten every time the schema changes again. Stepwise migrations (from -> to, one small transform each) compose: adding version 4 means adding one new migration, not touching the accumulated logic for 1→2→3. MigrationRunner just walks the chain from the config's current version to the target, applying each step in order.
API
new MigrationRunner(migrations)—migrations: { from, to, migrate }[].migrate(config, options?)— walks forward tooptions.targetVersion(default: latest registeredto).latestVersion()— highesttoamong registered migrations
Throws if no migration exists for the current version, or if the config's version is already newer than the target.
License
MIT
