Registry / database / migratex

migratex

JSON →
library1.3.0jsnpmunverified

Schema diff and migration engine for ORMs (Drizzle, Prisma, TypeORM). Current stable version is 1.3.0. It replaces linear migration files with a DAG-based approach using content-addressed IDs (SHA-256), enabling deterministic migrations, drift detection, and safe CI/CD workflows. Key differentiators: auto-generated SQL from ORM schema (no hand-written migrations), conflict detection at merge time, and support for Postgres and MySQL. Requires Node >=18.

npm install migratex
INSTALL
IMPORT
SIG · MIGRATEX
M
migratex
databasejavascriptv1.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import migratex from 'migratex'
const migratex = require('migratex')
ESM-only, no CJS support. Use top-level await for async operations.
check
import { check } from 'migratex/check'
import { check } from 'migratex'
check is a separate subpath export; direct import from 'migratex' will be undefined.
apply
import { apply } from 'migratex/apply'
const apply = require('migratex/apply')
apply is also a subpath export; use ESM only.

Shows initializing migratex, diffing schema, checking graph validity, applying migrations, and detecting drift — all using the programmatic API.

import migratex from 'migratex'; import { check } from 'migratex/check'; import { apply } from 'migratex/apply'; // Initialize (creates config and migrations folder) await migratex.init({ orm: 'drizzle', schemaPath: './db/schema', }); // Generate a migration from schema diff const migration = await migratex.diff(); console.log('Generated migration:', migration); // Validate the graph (CI step) const result = await check(); if (!result.valid) { console.error('Migration graph invalid:', result.errors); process.exit(1); } // Apply pending migrations await apply({ databaseUrl: process.env.DATABASE_URL ?? '', }); // Detect drift const drift = await migratex.detectDrift(); if (drift.detected) { console.warn('Drift detected:', drift.changes); }
Debug
Known issues
breakingMigratex v1 requires Node.js >=18. Earlier Node versions will fail to import due to top-level await and ESM.
fix
Upgrade Node to >=18.
affects: <1.0
deprecatedMigratex no longer supports CJS. require('migratex') returns undefined.
fix
Use ESM import syntax. If you must use CJS, consider a dynamic import inside an async function.
affects: >=1.0
gotchaThe 'check' and 'apply' functions are not exported from the main 'migratex' package — they are subpath exports.
fix
Import them from 'migratex/check' and 'migratex/apply' respectively.
affects: >=1.0
gotchaMigratex uses advisory locks for apply. On databases without advisory lock support (e.g., older MySQL), apply will fail.
fix
Ensure your database supports advisory locks (PostgreSQL, MySQL 5.7+). For unsupported databases, use the --no-lock flag.
affects: >=1.0
breakingMigration IDs changed from sequential numbers to SHA-256 content hashes in v1.0. Existing numbered migrations will be ignored.
fix
Recreate your migration history by running 'migratex init --rebase' to convert old migrations to DAG format.
affects: >=1.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Using ESM import in a CommonJS file without setting type:module in package.json.
fix
Add "type": "module" to your package.json or rename the file to .mjs.
Error: Cannot find module 'migratex/check'
Importing check from wrong path or using an older version that doesn't support subpath exports.
fix
Ensure you have migratex >=1.0.0 and import from 'migratex/check' (not 'migratex').
TypeError: migratex.init is not a function
Using require('migratex') which returns undefined because migratex is ESM-only.
fix
Use import migratex from 'migratex' inside an async context.
Error: Advisory lock not supported
Running migratex apply on a database that doesn't support advisory locks (e.g., MySQL <5.7).
fix
Upgrade MySQL to 5.7+ or use --no-lock flag (but risk race conditions).
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
migratex — npm install migratex · libregistry