Registry / database / lauf
library1.0.2jsnpmunverified

Lauf is a lightweight, TypeScript-native migration runner for PostgreSQL. Version 1.0.2 is the current stable release. It uses PostgreSQL to track migrations, guarantees consistency via transactions, and allows handling other databases or storages (e.g., S3, GCS) in migrations. Key differentiators: migration order is defined explicitly in code rather than implicitly through files, supports both up/down and latest mode, and has only a single runtime dependency (`pg`). The package ships TypeScript types and requires ESM.

npm install lauf
INSTALL
IMPORT
SIG · LAUF
L
lauf
databasejavascriptv1.0.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.

runMigrations
import { runMigrations } from 'lauf'
const { runMigrations } = require('lauf')
ESM-only; CommonJS require will fail.
Migration
import { Migration } from 'lauf'
import { migration } from 'lauf'
TypeScript type; named export with capital M.
MigrationsOptions
import { MigrationsOptions } from 'lauf'
import { MigrationOptions } from 'lauf'
TypeScript type for the options object; singular 'MigrationOptions' is incorrect.

Shows how to define and run a single migration using lauf with PostgreSQL.

import { runMigrations } from 'lauf'; import pg from 'pg'; const pgClient = new pg.Client({ connectionString: process.env.POSTGRESQL_URL ?? '' }); await pgClient.connect(); await runMigrations({ setup: async () => { await pgClient.connect(); return { pgClient }; }, teardown: ({ pgClient }) => pgClient.end(), migrations: [ { id: '2022-07-09-create-users', description: 'Create users', up: ({ pgClient }) => pgClient.query( `CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT);` ), down: ({ pgClient }) => pgClient.query(`DROP TABLE users;`), }, ], logger: (msg) => console.log(msg), });
Debug
Known issues
gotchaMigration order is defined by the array order, not by file names or timestamps.
fix
Ensure migrations are listed in the desired order in the `migrations` array.
affects: >=1.0.0
gotchaThe `setup` function must return an object that includes a `pgClient` property; otherwise migrations will fail.
fix
Make sure setup returns an object with at least `pgClient` as a `pg.Client` instance.
affects: >=1.0.0
deprecatedNo known deprecations in current version.
breakingNo breaking changes reported as of version 1.0.2.
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Using CommonJS require() instead of ESM import.
fix
Add 'type": "module" in package.json or use .mjs extension.
Error: setup must return an object with pgClient
setup function returns missing pgClient property.
fix
Return an object like { pgClient } from setup.
TypeError: pgClient.query is not a function
pgClient is not a proper pg.Client instance.
fix
Use new pg.Client() and connect before passing to runMigrations.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
pgrequiredRequired to connect to PostgreSQL and manage migration state.
Agent activity
4 hits · last 30 days
node
4
Resources
packagelauf
lauf — npm install lauf · libregistry