Registry / database / kysely-mig

kysely-mig

JSON →
library0.9.1jsnpmunverified

Kysely-Mig is a TypeScript-first command-line interface (CLI) tool designed to manage database migrations and seeding for PostgreSQL databases, built on top of the Kysely query builder. The current stable version is 0.9.1, indicating it's still in active development, likely with frequent updates as features are added or refined. Key differentiators include atomic operations, automatic rollback on errors, transaction support, migration locking, multi-environment configuration, and selective/partial migration execution. It provides both a robust CLI for schema evolution and a programmatic API for integrating migration logic directly into applications, simplifying database management for Kysely users.

npm install kysely-mig
INSTALL
IMPORT
SIG · KYSELY-MIG
K
kysely-mig
databasejavascriptv0.9.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

Migrator
import { Migrator } from 'kysely-mig';
const Migrator = require('kysely-mig');
The primary class for programmatic migration management. Use named import for ESM. CommonJS environments typically require `const { Migrator } = require('kysely-mig');` or an async import.
MigratorOptions
import { MigratorOptions } from 'kysely-mig';
import type { MigratorOptions } from 'kysely-mig';
This is an interface for configuring the Migrator class. While `import type` is generally preferred for types, `import { MigratorOptions } from 'kysely-mig';` also works as it's exported as a value in some contexts. The latter is provided for broader compatibility.
MigrationFile
import { MigrationFile } from 'kysely-mig';
Represents a migration file object, useful for programmatic listing or manipulation of migration states. Primarily a type, but exported as a value for consistency.

Demonstrates the initial setup, environment configuration, migration generation, and execution using the `kysely-mig` CLI.

npm install -g kysely-mig mig setup # Generate a database configuration file mig env generate local-db # Open 'local-db.env' and fill in your PostgreSQL connection details # Example: DATABASE_URL="postgres://user:password@host:port/database" # Add the configuration to kysely-mig's context and set it as default mig env add ./local-db.env -d # Verify the current environment is set mig env get # Generate a new migration file for 'users' table mig make users # Edit the generated migration file (e.g., migrations/timestamp_users.ts) // Example content for migrations/timestamp_users.ts: // import { Kysely, sql } from 'kysely'; // // export async function up(db: Kysely<any>): Promise<void> { // await db.schema // .createTable('users') // .addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`)) // .addColumn('email', 'varchar(255)', (col) => col.unique().notNull()) // .addColumn('username', 'varchar(255)', (col) => col.unique().notNull()) // .addColumn('created_at', 'timestamp', (col) => col.defaultTo(sql`now()`).notNull()) // .execute(); // } // // export async function down(db: Kysely<any>): Promise<void> { // await db.schema.dropTable('users').execute(); // } # Run all pending migrations mig up
kysely-mig --version
Debug
Known issues
gotchaThe package is currently in version 0.9.1. As a pre-1.0 release, it may introduce breaking changes in minor versions without strict adherence to semantic versioning principles, requiring careful review during updates.
fix
Always review the changelog before upgrading to new minor versions (e.g., from 0.9.x to 0.10.x) to identify potential breaking changes or API alterations.
affects: <1.0.0
gotchaConfiguration files and internal state are managed in the user's home directory (`$USER_HOME`). This can lead to issues in CI/CD pipelines, containerized environments, or multi-user setups where `$USER_HOME` might not be consistently available or writable, or where isolation is required.
fix
For CI/CD or container environments, ensure `$USER_HOME` is appropriately set and has write permissions, or consider manually copying configuration files into the expected location within the container/environment using a custom volume or initialization script.
affects: >=0.1.0
gotchaCurrently, kysely-mig is explicitly designed for PostgreSQL databases. Attempting to use it with other SQL dialects (e.g., MySQL, SQLite) will likely result in errors or unexpected behavior due to PostgreSQL-specific SQL generation and feature reliance.
fix
Ensure your project exclusively uses PostgreSQL. If you require other databases, consider alternative migration tools or monitor the kysely-mig roadmap for broader database support.
affects: >=0.1.0
gotchaGlobal installation (`npm install -g kysely-mig`) can lead to versioning conflicts if different projects on the same machine require distinct versions of the CLI tool. This can cause unexpected behavior or broken migrations.
fix
Consider installing `kysely-mig` as a `devDependency` in your project (`npm install --save-dev kysely-mig`) and running it via `npx kysely-mig` or through npm scripts (`"migrate": "kysely-mig up"`) to ensure project-specific versioning and avoid global conflicts.
affects: >=0.1.0
Errors
Common errors & fixes
mig: command not found
The `kysely-mig` CLI executable is not in your system's PATH, typically due to a failed global installation or a PATH configuration issue.
fix
Run `npm install -g kysely-mig` again. If the problem persists, check your npm global installation directory (e.g., `npm root -g`) and ensure it's included in your system's PATH environment variable.
Error: No database connection details found for current environment.
The migrator cannot find the `.env` configuration file for the currently selected environment, or no environment has been set as active.
fix
Ensure you have generated an environment file (`mig env generate <filename>`), filled in the database details, added it to the migrator's context (`mig env add <filename>`), and explicitly set it as the current environment (`mig env set <filename>`). Verify the environment name matches exactly.
Error: ENOENT: no such file or directory, open '.../.kysely-mig/envs/my-env.env'
The specified environment file could not be found by the `kysely-mig` CLI within its configuration directory, often due to an incorrect path during `mig env add` or the file being moved/deleted after being added.
fix
Verify the environment file exists at the path you provided to `mig env add`, and that the filename matches what's expected. You may need to remove (`mig env rm <filename>`) and re-add the environment if its location or name changed, or if there were file permission issues.
Upgrade
Version history
0.9.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
kysely-mig — npm install kysely-mig · libregistry