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.fixEnsure 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.fixMake 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.
fixAdd 'type": "module" in package.json or use .mjs extension.
Error: setup must return an object with pgClient
setup function returns missing pgClient property.
fixReturn an object like { pgClient } from setup. TypeError: pgClient.query is not a function
pgClient is not a proper pg.Client instance.
fixUse new pg.Client() and connect before passing to runMigrations.
Audit
Dependencies
pgrequiredRequired to connect to PostgreSQL and manage migration state.