Registry / database / kysely-migration-cli

kysely-migration-cli

JSON →
library0.4.2jsnpmunverified

A lightweight migration CLI library for Kysely, a TypeScript SQL query builder. Version 0.4.2 provides a `run()` function to build custom migration scripts with CLI commands (up, down, latest, create). Unlike full-fledged tools, it is a library that helps you create your own migration runner. Active development, supports ESM and CJS, integrates with Kysely's Migrator and FileMigrationProvider. Experimental no-script mode for Postgres with dotenv.

npm install kysely-migration-cli
INSTALL
IMPORT
SIG · KYSELY-MIGRATION-C
K
kysely-migration-cli
databasejavascriptv0.4.2
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.

run
import { run } from 'kysely-migration-cli'
const run = require('kysely-migration-cli')
ESM-only (no CommonJS). Use named import.
createMigration
import { createMigration } from 'kysely-migration-cli'
Available if exported, otherwise use run().
MigrationResult
import type { MigrationResult } from 'kysely-migration-cli'
import { MigrationResult } from 'kysely-migration-cli' (runtime error, no class)
Type-only export; use 'import type'.

Basic migration script setup: connect to Postgres, configure Kysely, and run CLI commands.

import * as path from 'path'; import { promises as fs } from 'fs'; import pg from 'pg'; import { Kysely, Migrator, PostgresDialect, FileMigrationProvider } from 'kysely'; import { run } from 'kysely-migration-cli'; const migrationFolder = path.join(__dirname, '../migrations'); const db = new Kysely({ dialect: new PostgresDialect({ pool: new pg.Pool({ connectionString: process.env.DATABASE_URL ?? '', }), }), }); const migrator = new Migrator({ db, provider: new FileMigrationProvider({ fs, path, migrationFolder, }), }); run(db, migrator, migrationFolder);
Debug
Known issues
gotchaThe `run` function expects the migration folder path as the third argument. Omitting it may cause runtime errors.
fix
Always pass the migration folder path explicitly.
affects: >=0.1.0
gotchaWhen using ESM, the migration folder path must be resolved with `new URL('../migrations', import.meta.url).pathname` instead of `__dirname`.
fix
Use `import.meta.url` to build the path in ESM environments.
affects: >=0.3.0
gotchaThe experimental no-script mode only supports Postgres. Using other dialects will fail silently.
fix
Stick to the script-based approach for non-Postgres databases.
affects: >=0.4.0
deprecatedThe `--template` option for custom migration templates is experimental and may change.
fix
Check the latest documentation for template support.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'kysely-migration-cli'
Missing installation or incorrect import path.
fix
Run `npm install kysely-migration-cli` and ensure the import statement matches the package name.
TypeError: run is not a function
Incorrect import (default instead of named) or CommonJS usage.
fix
Use `import { run } from 'kysely-migration-cli'` (ESM only).
Error: No migrations found
The `migrationFolder` path is incorrect or empty.
fix
Verify the folder exists and contains migration files. Use `path.join(__dirname, 'migrations')` for CJS or `new URL('./migrations', import.meta.url).pathname` for ESM.
Upgrade
Version history
0.4.2latest on npm
Audit
Dependencies
kyselyrequiredPeer dependency; required for migration types and Migrator class.
pgoptionalOptional dependency; needed for experimental no-script mode (Postgres dialect).
dotenvoptionalOptional; loads .env file automatically when present.
Agent activity
8 hits · last 30 days
node
8
Resources
kysely-migration-cli — npm install kysely-migration-cli · libregistry