Registry / database / adbm
library2.0.5jsnpmunverified

Simple, pluggable async database migration tool for Node.js >= 12.0.0. Current stable version is 2.0.5. It follows the UNIX philosophy of 'do one thing and do it well': it does not include a CLI for creating migration files. adbm is database-agnostic and requires an adapter for data persistence (e.g., adbm-mongodb). It supports both 'up' and 'down' migration directions, custom migration directories, exclusion of specific migrations, and injection of custom logging. Unlike other migration tools (e.g., migrate, db-migrate), adbm is lightweight, has no CLI, and relies on adapters for different databases. Released as needed; no fixed cadence.

npm install adbm
INSTALL
IMPORT
SIG · ADBM
A
adbm
databasejavascriptv2.0.5
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.

adbm
import { adbm } from 'adbm'
import adbm from 'adbm'
Named export, not default export. Also available via require: const { adbm } = require('adbm')
getMigrationObjectsFromDirectory
import { getMigrationObjectsFromDirectory } from 'adbm'
import { getMigrationObjects } from 'adbm'
Named export; used to read migration files from a directory. Defaults to this function if not overridden.
MigrationObject
import type { MigrationObject } from 'adbm'
TypeScript type for migration objects. Only import as type.

Connects to MongoDB, creates adbm instance with custom migrations directory, runs all pending migrations, and logs results.

import { adbm, getMigrationObjectsFromDirectory } from 'adbm' import { adapter } from 'adbm-mongodb' import { MongoClient } from 'mongodb' const client = await MongoClient.connect('mongodb://localhost:27017') const db = client.db('myDatabase') const migrate = adbm(db, adapter, { getMigrationObjects: args => getMigrationObjectsFromDirectory({ ...args, directory: 'custom/migrations' }) }) const migrations = await migrate({ direction: 'up', exclude: [] }) console.log(migrations) process.exit(0)
Debug
Known issues
gotchaMigration files must be CJS modules; ESM and TypeScript are not supported. Using .mjs or .ts files will cause errors.
fix
Use .js files with module.exports. For TypeScript, compile to .js or use ts-node with CJS mode.
affects: >=2.0.0
gotchaThe 'db' parameter passed to the adapter is the same as the migration functions. Ensure adapter functions expect the same database driver instance (e.g., MongoDB Db object).
fix
Verify adapters' signatures. For adbm-mongodb, pass the Db object from MongoClient.db().
affects: >=2.0.0
gotchaMigrations are identified by filename; files must be sorted correctly (e.g., 01-init.js, 02-add-index.js). adbm does not sort automatically; relies on filesystem order.
fix
Prefix filenames with numeric order (e.g., 001, 002) to ensure correct execution order.
affects: >=2.0.0
deprecatedThe 'getMigrationObjects' injection option is deprecated in favor of using getMigrationObjectsFromDirectory directly. Future versions may remove it.
fix
Pass custom getMigrationObjects function in the third argument as shown in the example, but be aware it may change.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: (0 , adbm.adbm) is not a function
Using default import instead of named import
fix
Change to: import { adbm } from 'adbm'
Error: Cannot find module 'adbm-mongodb'
Adapter package not installed
fix
Run: yarn add adbm-mongodb or npm install adbm-mongodb
TypeError: db.collection is not a function
Passed MongoClient instead of Db object to adbm
fix
Ensure you pass db = client.db() after connecting, not the client itself.
Upgrade
Version history
2.0.5latest on npm
Audit
Dependencies
adbm-mongodboptionalAdapter for MongoDB; required unless using custom adapter
Agent activity
48 hits · last 30 days
node
42
OpenAI (training)
1
Resources
packageadbm
adbm — npm install adbm · libregistry