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

simple-mysql-migrate

v2.0.0

Published

Dead simple MySQL schema migration for Node.js — scans a folder of .sql files and applies them in order, tracking applied versions in a schema_version table.

Readme

Simple-Mysql-Migrate

Dead simple database migration for SQL only

The principle is similar to Flyway and similar tools, except it's VERY basic and runs in a few lines of code for Node.js. MySQL only.

Install

npm install simple-mysql-migrate mysql2

mysql2 is a peer dependency.

Usage

TypeScript:

import DbMigrate from 'simple-mysql-migrate';

const migration = new DbMigrate({
    host: '127.0.0.1',
    port: 3306,            // optional, default 3306
    username: 'my_user',
    password: 'my_password',
    database: 'my_database_name',
    timezone: '+00:00',    // optional, default '+00:00'
    connectionLimit: 50,   // optional, default 50
    migrationPath: '/path/to/migrations', // optional, can also use setMigrationPath()
});

try {
    await migration.migrate();
} finally {
    await migration.close();
}

JavaScript:

const DbMigrate = require('simple-mysql-migrate').default;

const migration = new DbMigrate({
    host: '127.0.0.1',
    username: 'my_user',
    password: 'my_password',
    database: 'my_database_name',
});

migration.setMigrationPath('/path/to/migrations');
migration.migrate()
    .catch((err) => { console.error(err); process.exitCode = 1; })
    .finally(() => migration.close());

How it works

It scans the directory for .sql files, sorts them by numeric version, and runs each file that hasn't already been applied. A schema_version table tracks what has been run.

Filenames must match v<version>__<description>.sql, for example v1.2.5__new_user_table.sql. The version is dotted numeric and is sorted numerically (so v10.0.0 runs after v2.0.0, not before). Underscores in the description are turned into spaces.

Each .sql file is executed as a single multi-statement query, so feel free to put several ;-separated statements in one file.

Failure behaviour

If a migration fails, migrate() throws and a row is recorded in schema_version with a non-zero status and the error message in reason. Subsequent runs will refuse to proceed until you fix the SQL and remove the failed row manually. This is intentional — silently retrying a half-applied migration is dangerous.

⚠ MySQL implicitly commits before and after each DDL statement (CREATE, ALTER, DROP, etc.), so a multi-DDL migration that fails partway through is not automatically rolled back. Keep migrations small and idempotent where possible.

Concurrency

A MySQL GET_LOCK advisory lock (simple-mysql-migrate) is acquired for the duration of migrate(), so it is safe to start multiple processes simultaneously — only one will run migrations at a time.

Custom logger

const migration = new DbMigrate({
    /* ... */
    logger: {
        log:   (m) => myLogger.info(m),
        error: (m) => myLogger.error(m),
    },
});

Pass logger: null to silence all output.