Registry / database / mysql-migration-promise

mysql-migration-promise

JSON →
library0.3.1jsnpmunverified

A promise-based MySQL migration utility for Node.js, version 0.3.1. It provides a simple API to run SQL migration scripts automatically on application startup. The package enforces a naming convention (V<version>__<name>.sql) and supports single or multiple statements per file depending on connection settings. Compared to alternatives like db-migrate or knex, it is minimal and focused, but lacks CLI tools, rollback support, and active maintenance.

npm install mysql-migration-promise
INSTALL
IMPORT
SIG · MYSQL-MIGRATION-PR
M
mysql-migration-promise
databasejavascriptv0.3.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.

default
const mysqlMigration = require('mysql-migration-promise');
import mysqlMigration from 'mysql-migration-promise';
Package is CommonJS-only; ESM import will fail. Use require() or dynamic import.
init
const migrationService = await mysqlMigration.init(connection, './migrations');
mysqlMigration.init(connection, './migrations');
init() is async and returns a promise; must be awaited or used with .then().
migrate
await migrationService.migrate();
migrationService.migrate();
migrate() is async and returns a promise; must be awaited.

Initializes a MySQL connection, runs migrations from the ./migrations folder, and closes the connection.

const mysql = require('mysql2'); const mysqlMigration = require('mysql-migration-promise'); async function runMigrations() { const connection = mysql.createConnection({ host: 'localhost', user: 'root', password: 'root', database: 'mydb', multipleStatements: true }); const migrationService = await mysqlMigration.init(connection, './migrations'); await migrationService.migrate(); console.log('Migrations completed successfully.'); connection.end(); } runMigrations().catch(err => console.error(err));
Debug
Known issues
gotchaMultiple SQL statements in a single migration file are not supported unless multipleStatements option is enabled in the MySQL connection.
fix
Either enable multipleStatements: true in the connection config, or split migration scripts into separate files with single statements.
affects: >=0.1.0
gotchaMigration files must follow the naming convention V<version>__<name>.sql (e.g., V1__init.sql). Files that do not match are ignored.
fix
Rename migration files to match the required pattern.
affects: >=0.1.0
gotchaThe init() function expects an absolute or relative path to the migrations folder. If relative, it is resolved from the current working directory, not the module's location.
fix
Use __dirname + '/migrations' to ensure the path is relative to the calling file.
affects: >=0.1.0
gotchaThere is no rollback or undo functionality; migrations are only applied forward.
fix
Manually revert changes or use a more feature-rich migration tool if rollback is needed.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'mysql-migration-promise'
The package is not installed or require path is incorrect.
fix
Run: npm install mysql-migration-promise
Error: init is not a function
The import method does not match the module export (e.g., using ES6 import when module uses CommonJS).
fix
Use: const mysqlMigration = require('mysql-migration-promise');
Error: Migration file name does not match pattern V<version>__<name>.sql
The migration file name is not in the required format.
fix
Rename the file to something like V1__init.sql.
Upgrade
Version history
0.3.1latest on npm
Audit
Dependencies
mysql2requiredUsed for database connections; the library depends on the mysql2 API for creating connections and querying.
Agent activity
9 hits · last 30 days
node
8
Resources
mysql-migration-promise — npm install mysql-migration-promise · libregistry