Registry / database / anydb-sql-migrations

anydb-sql-migrations

JSON →
library2.4.1jsnpmunverified

A migration tool for anydb-sql, providing up/down migration functions with transaction support. The current stable version is 2.4.1. It is a lightweight, synchronous-style migration runner that operates within database transactions, allowing safe rollbacks. It includes CLI commands for checking and executing pending migrations, with an option for silent mode. It ships TypeScript definitions and is intended for use with anydb-sql databases.

npm install anydb-sql-migrations
INSTALL
IMPORT
SIG · ANYDB-SQL-MIGRATIO
A
anydb-sql-migrations
databasejavascriptv2.4.1
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.

migrate
import migrate from 'anydb-sql-migrations'
const migrate = require('anydb-sql-migrations')
CommonJS require works but ESM import is recommended for TypeScript projects.
create
const migration = require('anydb-sql-migrations').create(db, dir)
const migration = require('anydb-sql-migrations').create(db)
Second argument (path to migrations directory) is required; omitting it leads to errors.
run
migration.run()
migration.run({ silent: true }) // not wrong but optional config
run() executes pending migrations; it can accept an options object with silent: true.
migrate
migration.migrate({ silent: true })
migration.migrate() // missing options object happens but optional
migrate() is similar to run() but returns a promise. Options object is optional.

Sets up a migration script using anydb-sql and anydb-sql-migrations, including database connection and migration execution.

#!/usr/bin/env node const anydbSQL = require('anydb-sql'); const path = require('path'); // Create your database instance const db = anydbSQL({ url: process.env.DATABASE_URL ?? 'postgres://user:pass@localhost/mydb' }); // Create migration instance const migration = require('anydb-sql-migrations').create( db, path.resolve(__dirname, 'migrations') ); // Check if any migrations are pending migration.check(); // Execute pending migrations migration.run();
Debug
Known issues
gotchaMigrations must be placed in a directory and referenced correctly; otherwise the tool will fail to detect any migration files.
fix
Ensure the second argument to create() is a valid path to a directory containing .js files with exports.up and exports.down.
affects: >=2.0.0
gotchaThe migration functions up/down receive a transaction object, not a database connection. Using the connection directly inside these functions will bypass transactional safety.
fix
Use the provided transaction object for all database operations inside up/down functions.
affects: >=2.0.0
deprecatedThe package may be considered deprecated in favor of more modern migration tools like Knex or TypeORM, given anydb-sql's limited maintenance.
fix
Consider migrating to a more actively maintained migration framework.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: migration.run is not a function
Missing or incorrect import; likely using the default import incorrectly or forgetting to call create().
fix
const migration = require('anydb-sql-migrations').create(db, dir); migration.run();
Error: Cannot find module './001-empty-test'
Migration file path is incorrect or the migration directory is not properly set.
fix
Ensure the second argument to create() points to the correct directory containing migration files.
Error: Transaction is not available
Attempting to use database operations outside the transaction object passed to up/down functions.
fix
Use the transaction parameter inside exports.up = function(t) { t.queryAsync('...'); }
Upgrade
Version history
2.4.1latest on npm
Audit
Dependencies
anydb-sqlrequiredPeer dependency required to create a database instance for migrations.
Agent activity
17 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
anydb-sql-migrations — npm install anydb-sql-migrations · libregistry