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 🙏

© 2024 – Pkg Stats / Ryan Hefner

iplayabc-db-migration

v1.0.11

Published

MySQL Database migration tool

Downloads

213

Readme

iplayabc-db-migrate

A simple and efficient database migration tool for MySQL databases.

Prerequisites

  • Node.js(12.8.0+)
  • MySQL database
  • Required Node.js packages: umzug, mysql2 (or whatever MySQL client you're using)

Installation

Install the package using npm:

npm install iplayabc-db-migrate

You could refer to https://iplayabc.coding.net/p/huaweicloud/artifacts/25067203/npm/packages?hash=85b1301efbde44f996542be55f6db677 if you meet credential problems.

Usage

  1. First, ensure you have a config.js file in your project with a db property containing your database configuration:
  2. Create a db-migration/migrations folder in your project root to store your SQL migration files.
  3. In your main server file (e.g., server.js), import and use the migration tool:
const db_migrate = require('iplayabc-db-migrate');
async function startServer() {
    try {
        await db_migrate('config.js');
        console.log('Database migration completed successfully');
        // Continue with your server setup
    } catch (error) {
        console.error('Migration failed:', error);
        process.exit(1);
    }
}
startServer();

Configuration

This module supports customizing the migration table name through the configuration file.

Migration Table Name

You can set the migration table name in your config file. If not specified, the default table name 'migrations' will be used. Example config.js:

exports.migration_table = 'migrations'

SQL File Naming Convention

Name your SQL migration files using the following format:

YYYYMMDDHHMMSS_description.sql

For example:

  • 20230615120000_create_users_table.sql
  • 20230616093000_add_email_to_users.sql

Running Migrations

Migrations will run automatically when you call db_migrate() in your code. This function returns a promise, so you can await it or use .then() syntax.

The tool will:

  1. Check for any new migration files that haven't been executed yet.
  2. Execute these new migrations in order.
  3. Record the executed migrations in a migrations table in your database.

Error Handling

If a migration fails, the tool will log the error and stop the migration process. It's important to handle these errors in your application code, as shown in the usage example above.

Best Practices

  1. Always review migration files before executing them.
  2. Test migrations in a non-production environment first.
  3. Keep migrations small and focused on a single change.
  4. Use descriptive names for your migrations.
  5. Include both "up" and "down" migrations when possible for reversibility.

Important: Modifying or deleting migration files that have already been executed can lead to inconsistencies between your database state and migration history. If you need to make changes, create a new migration instead.