npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

mysql-migration

v1.2.6

Published

Migration for mysql database

Downloads

275

Readme

🗄️ MySQL Migration Database

A command-line companion that helps you manage versioned MySQL schema changes from your Node.js projects.

npm version   License   Node.js


✨ Features

  • 🎯 Multi-database support — Orchestrate migrations across different environments
  • ⏱️ Timestamped migration files — Generated with a single command
  • Forward and backward execution — Run or roll back batches confidently
  • 🔧 Scriptable CLI — Plugs into CI/CD pipelines via standard Node.js tooling
  • 📦 Zero dependencies — Lightweight and fast

📋 Prerequisites

  • Node.js v18 or later.
  • MySQL instance reachable from where you run the CLI.
  • A project workspace where you can store migration files and configuration.

📦 Installation

Install locally within your project:

npm install --save-dev mysql-migration

Or run ad hoc without installing by prefixing commands with npx.

🚀 Quick Start

1️⃣ Initialize the project

Run the init command to scaffold the migrations/ directory and create a default configuration file:

npx mysql-migration init

2️⃣ Configure your database

Edit the generated migrations/mysql-migration.config.json file with your database credentials.

3️⃣ Generate your first migration

npx mysql-migration create add_users_table main-db

4️⃣ Apply pending migrations

npx mysql-migration run main-db

⚙️ Configuration

The CLI reads settings from mysql-migration.config.json. Define each database you manage inside the databases object. Every entry requires the connection credentials documented below:

  • host: MySQL server host name or IP.
  • database: Database schema name.
  • user: User with migration privileges.
  • password: Corresponding password.
{
  "databases": {
    "db_name": {
      "host": "db_host",
      "user": "db_user",
      "password": "db_password",
      "database": "db_name"
    }
  }
}

Add as many database entries as you need. You can then target each one via the CLI commands below.

📖 Usage

📝 Available Commands

| Command | Description | |---------|-------------| | npx mysql-migration help | 📚 Show all available commands | | npx mysql-migration init | 🎬 Scaffold migrations directory and config | | npx mysql-migration create <name> <dbName> | ✏️ Scaffold a timestamped migration file | | npx mysql-migration run [dbName] | ▶️ Execute all pending migrations | | npx mysql-migration rollback <dbName> <batch> | ⏪ Roll back migrations to specified batch | | npx mysql-migration batch <dbName> | 📊 Display recorded batches | | npx mysql-migration to-cjs <dbName> | 🔄 Convert migrations to CommonJS | | npx mysql-migration to-esm <dbName> | 🔄 Convert migrations to ESM |

🎬 Initialize Project

npx mysql-migration init

Scaffolds the migrations/ directory and creates a default mysql-migration.config.json file. Run this once when setting up the tool in a new project.

✏️ Create a New Migration

npx mysql-migration create migration-name database-name

A new file appears in the migrations/ directory, timestamped and ready for your SQL up and down statements.

▶️ Run Pending Migrations

npx mysql-migration run database-name

All migrations that have not yet been applied will run sequentially for the selected database.

⏪ Roll Back Migrations

npx mysql-migration rollback database-name batch

Use this when you need to revert the database state to the specified batch number.

📊 Inspect Batches

npx mysql-migration batch database-name

View the recorded batches to understand which migrations were executed together.

🔄 Convert Module System

If you need to switch your project between CommonJS (require) and ES Modules (import/export), you can batch convert your existing migration files.

Convert to CommonJS:

npx mysql-migration to-cjs database-name

Convert to ES Modules:

npx mysql-migration to-esm database-name

🔧 Troubleshooting

  • Authentication errors: Verify credentials in mysql-migration.config.json match your MySQL user.
  • Connection refused: Ensure the MySQL server accepts remote connections from your host and the port is open.
  • Missing migrations folder: Run npx mysql-migration init to scaffold the migrations/ directory and configuration file.

💬 Support

Use npx mysql-migration help to review commands, or open an issue on the repository if you encounter bugs or have enhancement ideas.


📄 License

This project is distributed under a custom non-commercial license. Please review LICENSE.md for the full terms before using the software.

Made with ❤️ by SherKan