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

abstract-migrate

v2.4.0

Published

Storage-agnostic migration runner

Downloads

175

Readme

abstract migrate

Abstract migrate is a data-agnostic tool for running scripts (e.g., migrations) once.

Usage

Install with yarn:

$ yarn global add abstract-migrate

or npm:

$ npm i -g abstract-migrate

Now you can execute the provided CLI interface:

$ abstract-migrate --help

or

$ am --help

Create an Engine

This library was written to be storage agnostic. You will need to write some code to tell abstract-migrate how to store details about things it has ran. Your engine is expected to export five methods:

module.exports = {
  // Returns all of the loaded migrations from your storage in the format:
  // [{ name, timestamp }, ...] 
  load: function(/* cb */) {
    // ...
  },
  
  // Persist a collection of migrations to your storage. Migrations will be an array in the same
  // format as the `load` function: [{ name, timestamp }, ...]
  add: function(migrations/*, cb */) {
    // ...
  },
  
  // Remove a collection of migrations to your storage. Migrations will be an array in the same
  // format as the `load` and `add` function: [{ name, timestamp }, ...]
  remove: function(migrations/*, cb */) {
    // ...
  },
  
  // Ask the storage for a lock to prevent running migrations multiple times. This function should
  // return `true` if it was able to acquire a lock or `false` otherwise.
  acquireLock: function(/* cb */) {
    // ...
  },
  
  // This will denote that the process is done and the storage engine can release whatever lock it
  // acquired earlier.
  releaseLock: function(/* cb */) {
    // ...
  },
};

All of the above functions can return a promise that resolves to the desired value, or use the callback that is passed as the last argument to every engine function.

There is a basic filesystem engine that can be used as an example engine implementation.

Caution: Pay extra attention to make your acquireLock function is atomic so that it does not create a race condition where two simultaneous executions can acquire a lock at the same time. If there is no case where this command will be run multiple times, you can "ignore" locking by immediately resolving your acquireLock function to true.

Configuration

Now that you have your engine, you will need to tell abstract-migrate how to use it. You can configure this library via the command line interface (see the CLI help output am --help) or via a JSON file. Using the JSON file is the recommended option. By default, this library will look for a file named .abstract-migrate.json, but you can configure this location using the CLI. The configuration file accepts the following options:

  • engine: The migration storage engine to use
  • require: A JavaScript file (or array of files) to require before running
  • noColor: Disables color output (default: false)
  • migrationPath: The directory where migration files are stored (default: migrations)

Example .abstract-migrate.json

{
  "engine": "./src/postgresEngine.js",
  "require": "babel-register",
  "migrationPath": "db/migrations",
  "noColor": true
}

Commands

create

$ am create my-cool-migration

This command will create a migration of the given name in the migrations folder. The migration will be a simple file that exports an up and down function. The up and down functions can either return a promise or call the provided callback function.

list (alias: ls)

$ am list

This command will list all of the migrations in the migration directory and denote whether or not a given migration has been run.

up

$ am up

This command will run all of the unran migrations. You can pass the --ignore-past (-p) to not run migrations that are older than the most recently successful migration.

You can specify a migration name to migrate up to and including the named migration:

$ am up 1492708337968-my-cool-migration

or specifying the number of migrations to apply:

$ am up 2

or specifying exactly one migration to apply:

$ am up --only 1492708337968-my-cool-migration

You can pass the --dry-run (-d) flag to preview which migrations will be run.

down

$ am down 2

This command will roll back the specified number of migrations. You can also specify a migration name to migrate down to and including the named migration:

$ am down 1492708337968-my-cool-migration

or specifying exactly one migration to run down:

$ am down --only 1492708337968-my-cool-migration

You can pass the --dry-run (-d) flag to preview which migrations will be run down.

rollback

$ am rollback

This command will undo the most recently applied set of migrations. You can pass the --dry-run (-d) flag to preview which migrations will be run down.