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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mysql2-migrations

v3.4.1

Published

Create and manager migrations with mysql2 in module type apps

Readme

Mysql2 Migrations :: Type module projects

  • Create and manager migrations with mysql2 from repositories with configuration "TYPE MODULE"

📫 Disclaimer

  • This package must be used with MODULE TYPE IMPORT AND FROM
  • Set config on package.json "type": "module"

🧠 Configuration

  • step 1

    • Install dependencies
    • Should install 'mysql2' dependency in your projects first
    npm i mysql2
    npm i mysql2-migrations
  • step 2

    • Execute script to add files configuration in environment (reminder: add credentials in Migration instance on finalize)
    npx mysql2-migrations init
  • step 3 (Optional configure environment yourself)

    • 1.Create a folder in root app with name "mysql2-migrations"
    • 2.Create a "migrations_config.js" file in "mysql2-migrations" folder with next configuration(add your db credentials here)
    import Migration from 'mysql2-migrations'
      
    const db_query = new Migration()
    db_query.database = "test"
    db_query.user = "root"
    db_query.password = "password"
    db_query.host = "127.0.0.1"
    db_query.port = 3306
    db_query.name_table_migrations = "table_migrations_app" // two characters minimum
    db_query.show_query = true
    db_query.skip_migration_error = true // use for skip some migration file with some error and continue with the rest of migration files, but this can cause          problems if the error is in the query and not in the migration file, example: when use migrations files without "down" query
    db_query.show_depuration = true // show depuration on finalize migration, recommended
    db_query.start()
    • 3.Create a subfolder "migrations" into "mysql2-migrations" folder:

      • root_app/
        • mysql2-migrations/
          • migrations_config.js
          • migrations/
    • 4.Add scripts commands to package.json configuration:

    "scripts": {
        "db_create": "node mysql2-migrations/migrations_config.js create",           
        "db_refresh": "node mysql2-migrations/migrations_config.js refresh",                
        "db_migrate_all": "node mysql2-migrations/migrations_config.js migrate",   
        "db_migrate": "node mysql2-migrations/migrations_config.js up",                   
        "db_rollback": "node mysql2-migrations/migrations_config.js down",
        "db_status": "node mysql2-migrations/migrations_config.js status"              
    }

👋 Description script commnads

  • db_create

    Create file to migrate:

    npm run db_create create_users_table
    npm run db_create alter_sales_table

    Edit migration file with query

  • db_migrate

    Migrate last file pending:

    npm run db_migrate

    Migrate file with index: (check index with "npm run db_status")

    npm run db_migrate <index>
  • db_migrate_all

    Migrate all files pending:

    npm run db_migrate_all

    If already exists:

  • db_rollback

    Undo latest migration:

    npm run db_rollback

    Undo migration with index: (check index with "npm run db_status")

    npm run db_rollback <index>
  • db_status

    Check migrations integrity, check indexes of pending and executed migrations:

    npm run db_status
  • db_refresh

    Undo and redo all migrations (CAUTION DATA LOSS, It is not recommended to do it ):

    npm run db_refresh
  • too You can also UP or DOWN direct migrations

    DIRECT MIGRATIONS WILL NOT BE SAVED IN THE "table_migrations_app" TABLE

    Don't mixed direct migrations with stored migrations in database

    Use this function only for execute some querys that are not necessary to be stored in the database and that you are sure that will not cause problems in the future.

    This file name is example(image), dont use timestamp, you can to use unformatted names in files: example: "direct_create_users_table.js"

    Example type up:

    node mysql2-migrations/migrations_config.js run direct_create_users_table.js up

    Example type down:

    node mysql2-migrations/migrations_config.js run direct_create_users_table.js down

🔥 Others

  • Help
npx mysql2-migrations help