Registry / database / migralite

migralite

JSON →
library1.2.0jsnpmunverified

Migralite is a lightweight, forward-only SQLite migration tool for Bun, currently at v1.2.0 with a stable release cadence. It simplifies database schema evolution by using simple .sql files as migration scripts, wrapping each migration in a transaction, and tracking applied versions to prevent duplicate runs. Unlike general-purpose migration tools like dbmate or Flyway, Migralite is specifically built for the Bun runtime, offers a CLI with sensible defaults, a migration generator, and can be used as a library for programmatic control. Key differentiators include its minimal design, Bun-native integration, and focus on forward-only migrations for simplicity.

npm install migralite
INSTALL
IMPORT
SIG · MIGRALITE
M
migralite
databasejavascriptv1.2.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.

applyMigrations
import { applyMigrations } from 'migralite'
const applyMigrations = require('migralite').applyMigrations
Migralite is ESM-only; CommonJS require() will fail.
connectToDatabase
import { connectToDatabase } from 'migralite'
import connectToDatabase from 'migralite'
connectToDatabase is a named export, not default.
Database
import { Database } from 'bun:sqlite'
import Database from 'bun-sqlite'
Use Bun's built-in sqlite module, not a third-party package.

Demonstrates applying SQLite migrations using Migralite, including database initialization and error handling.

// Initialize a SQLite database and run migrations import { Database } from "bun:sqlite"; import { applyMigrations } from "migralite"; const db = new Database(":memory:"); // or connect to a file: new Database("./data.db"); try { await applyMigrations(db, "./migrations"); console.log("Migrations applied successfully"); } catch (err) { console.error("Migration failed:", err); } // Also connect to an existing database: // import { connectToDatabase } from "migralite"; // const db = connectToDatabase("./path/to/db.sqlite"); // await applyMigrations(db, "./migrations");
Debug
Known issues
gotchaMigration filenames must follow the format: YYYYMMDDHHMMSS__description.sql (e.g., 20240815123456__create-users-table.sql). Other formats will cause an error and migrations will not run.
fix
Use the --generate command to create correctly formatted filenames, or manually name files following the strict pattern.
affects: >=1.0.0
gotchaMigrations are forward-only; there is no down/rollback support. Once applied, migrations cannot be undone.
fix
Test migrations carefully before applying to production. Consider using a staging environment.
affects: >=1.0.0
gotchaMigralite is ESM-only and requires Bun; it will not work in Node.js or Deno. CommonJS require() will throw a Module not found error.
fix
Ensure your project uses Bun and uses ESM import syntax.
affects: >=1.0.0
gotchaThe peer dependency typescript is required for development; omitting it may cause type errors in TypeScript projects.
fix
Install TypeScript: bun add -d typescript
affects: >=1.0.0
Errors
Common errors & fixes
Error: Migration file '...' does not match expected pattern. Expected format: YYYYMMDDHHMMSS__*.sql
Migration filename does not follow the required YYYYMMDDHHMMSS__description.sql pattern.
fix
Rename the migration file to match the pattern, e.g., 20240815123456__my-migration.sql, or use --generate to create correct filenames.
TypeError: migrate is not a function
Incorrect import path or using CommonJS require() in an ESM-only package.
fix
Use import { applyMigrations } from 'migralite' with ESM syntax in a Bun environment.
error: Module not found "migralite"
Migralite is not installed, or the import path is wrong.
fix
Install migralite using 'bun add -d migralite' and ensure the import path is correct (e.g., 'migralite').
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
typescriptoptionalPeer dependency required by the package for type definitions
Agent activity
8 hits · last 30 days
node
8
Resources
migralite — npm install migralite · libregistry