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

mysql2-migrations

v3.3.2

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"
  • NO compatible with MODULE.EXPORT AND REQUIRE

🧠 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.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
  • db_migrate_all

    Migrate all files, Execute first time after initialize repository:

    npm run db_migrate_all

    If already exists:

  • db_rollback

    Undo latest migration:

    npm run db_rollback
  • db_status

    Check migrations integrity:

    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

    Example type up:

    node mysql2-migrations/migrations_config.js run 1763854407404_create_users_table.js up

    Example type down:

    node mysql2-migrations/migrations_config.js run 1763854407404_create_users_table.js down

👩‍💻 Add file migrations

  • Add file to migrate:

    npm run db_create create_users_table 
  • Go to "migrations" folder and edit file with query(should contain up and down query or only up):

    export default {
        "description":"Create Users Table",
        "up":
            `
            CREATE TABLE users(
                user_id BIGINT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
                name VARCHAR(100) NOT NULL,
                surname VARCHAR(100) NOT NULL,
                created_at DATETIME(6) NOT NULL,
                updated_at DATETIME(6) NOT NULL,
                PRIMARY KEY (user_id),
                UNIQUE INDEX user_id_UNIQUE (user_id ASC) VISIBLE)
            `
        ,
        "down":"DROP TABLE users"
    }

⚡️ Run migrations

  • Finally, run the migration with the command:
npm run db_migrate

🔥 Others

  • Help
npx mysql2-migrations help