Registry / database / knex-migrate

knex-migrate

JSON →
library1.7.4jsnpmunverified

Modern migration toolkit for knex.js (v1.7.4) that provides a command-line interface and programmatic API for managing database migrations with knex. It offers features such as migrating to any version, running individual migrations, rolling back recent migrations, redo for quick testing, and transaction-based execution. It is fully compatible with knex.js's migration CLI and supports environment-specific configuration via knexfile. The package is actively maintained with peer dependency on knex, requiring Node >= 8.

npm install knex-migrate
INSTALL
IMPORT
SIG · KNEX-MIGRATE
K
knex-migrate
databasejavascriptv1.7.4
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 knexMigrate from 'knex-migrate'
const knexMigrate = require('knex-migrate')
Package uses ESM default export; CommonJS require will still work but TypeScript may require default import.
knexMigrate
import knexMigrate from 'knex-migrate'
import { knexMigrate } from 'knex-migrate'
The package exports a single default function, not a named export.
Type definition (TypeScript)
import knexMigrate from 'knex-migrate'
import knexMigrate from 'knex-migrate' // no types shipped
knex-migrate does not include TypeScript definitions; use @types/knex or define own.

Shows programmatic usage of knex-migrate with knex setup and migration commands.

import knex from 'knex'; import knexMigrate from 'knex-migrate'; const db = knex({ client: 'sqlite3', connection: { filename: './mydb.sqlite' } }); async function run() { const log = ({ action, migration }) => console.log(`Doing ${action} on ${migration}`); await knexMigrate('up', { to: '20200101000000' }, log); await knexMigrate('down', { step: 2 }, log); await knexMigrate('redo', { verbose: true }, log); } run().catch(console.error);
Debug
Known issues
gotchaPackage requires knex as a peer dependency and will fail silently if knex is not installed.
fix
Install knex: npm install knex
affects: >=1.0.0
gotchaMigrations run in transactions by default; raw option disables transactions but may cause partial migrations.
fix
Use --raw with caution or ensure migration logic is idempotent.
affects: >=1.0.0
deprecatedUsing `require('knex-migrate')` instead of default import may cause confusion in TypeScript projects.
fix
Use import knexMigrate from 'knex-migrate'
affects: >=1.0.0
gotchaThe `--to` flag accepts migration name or version string; omitting it for 'up' migrates to the latest version.
fix
Specify version explicitly to avoid unintended migrations.
affects: >=1.0.0
gotchaProgrammatic API does not support all CLI flags; notably `cwd`, `knexfile`, `migrations`, `env` are not available.
fix
Use knexfile configuration for path settings.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'knex'
Missing peer dependency knex
fix
npm install knex
TypeError: knexMigrate is not a function
Incorrect import (named instead of default)
fix
Use: import knexMigrate from 'knex-migrate'
Error: Migration file not found
Migrations directory path is wrong or environment variable not set
fix
Set correct knexfile or provide --migrations path
Error: knex is not a constructor
Using wrong knex import (CommonJS vs ES module)
fix
Use: const knex = require('knex');
Upgrade
Version history
1.7.4latest on npm
Audit
Dependencies
knexrequiredPeer dependency required for migration functionality
Agent activity
7 hits · last 30 days
node
6
Resources
knex-migrate — npm install knex-migrate · libregistry