db-migrator is a complete and easy-to-use database migration tool for Node.js projects, offering robust support for both PostgreSQL and MySQL databases. The current stable version is 2.4.0, and based on its active GitHub repository, it appears to maintain an ongoing, though not explicitly defined, release cadence. A key differentiator is its comprehensive feature set, including automatic migration from scratch to the latest version, granular step-by-step forward and backward migration capabilities, and the ability to migrate to a specific database version. It supports deep searching for migration scripts within subfolders and ensures data integrity through transactional "all or nothing" execution, where failures result in a full rollback. This tool builds upon its `pg-migrator` predecessor by introducing timestamp-based version IDs, storing execution times, allowing descriptive migration file names, favoring `npm` scripts for execution, and crucially, adding support for MySQL. It mandates Node.js v7.6.0 or higher due to its reliance on `async/await` syntax in its codebase.
npm install db-migratorNo compatibility data collected yet for this library.
This quickstart demonstrates how to integrate db-migrator into your project using npm scripts, configure your database connection via .npmrc, and use the primary CLI commands for creating, migrating, rolling back, and checking migration status.
Upgrade your Node.js runtime environment to version 7.6.0 or later.
Remove all transaction control statements (e.g., `BEGIN`, `COMMIT`, `ROLLBACK`) from your migration SQL scripts.
To alter a PostgreSQL ENUM type, a common workaround involves changing the column's type to `VARCHAR`, recreating the ENUM with the new values, and then changing the column's type back to use the updated ENUM. This sequence must be handled carefully within your migration script.
Grant the necessary database privileges (e.g., `CREATE`, `ALTER`, `DROP` for schema changes, `SELECT`, `INSERT`, `UPDATE`, `DELETE` for data manipulation) to the database user configured for `db-migrator`.
Ensure you have `db-migrator` installed locally (`npm install db-migrator`) and are running the commands through your `package.json` scripts, e.g., `npm run db-migrate`.
Install the appropriate database driver for your chosen database: `npm install pg --save` for PostgreSQL, or `npm install promise-mysql --save` for MySQL.
Manually create the database (e.g., `createdb your_database_name` for PostgreSQL, or `CREATE DATABASE your_database_name;` for MySQL) before attempting to run migrations.
Review and update the permissions granted to the database user. Ensure the user has sufficient privileges for schema modifications and data operations on the target database.