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

redcrab

v2.0.1

Published

DB migration tool built on top of muckraker

Readme

Redcrab

Greenkeeper badge

Postgresql DB Migrator built off of pg-promise

CLI

Coming soon.

Usage

r = new Redcrab(options);
r.create(type, name); //Create new migration file
r.forward(); //Migrate the db forward as far as it will go
r.backward(); //Migrate the db backward one migration

Options

  • connection (default: undefined) Passed to pg-promise to make a connection to the database
  • advisory_lock (default: 72656463726162) Unique number for advisory locks. See the note about database concurrency below.
  • schema_start (default: 10000) This is the number that migrations will start with
  • table_name (default: redcrab_migrations) Database table to store migration metadata in (i.e. which migrations have run)
  • template_directory (default: ./templates) Directory to use for migration templates
  • migration_directory (default: ./migrations) Directory to use for migration files
  • db (default: internal) pg-promise connection to use for operations. A reason to override this would be if you have other running code that also connects through pg-promise and you want to avoid the error it gives when instantiating it twice.
  • pg (default: undefined) Parameters to pass to pg-promise when instantiating it before making the connection to the database. If db is present as an option this is ignored.

Create

r.create(type, name);

type (default: yaml) specifies the type of migration to make. The currently supported types are js and yaml. The appropriate template for either type will be copied from the templates directory when making the new migration. name (default: "migration") specifies the non-numbered part of the migration filename. This should be a very short word or phrase used to generally indicate information about the migration. Detailed information will go inside the migration file itself under its description field.

New migrations are made using the next highest schema number, as defined by the migration files that already exist. If none are found then schema_start is used.

So, for example

r.create('foo');

Will create a file in the migrations directory named 10000-foo.yaml, if no other migrations are found. Running it again:

r.create('bar');

Will create a file in the migrations directory named 10000-bar.yaml. Migrations are ran in the order of the number the filename starts with, this number is required. The number must be unique, no two files can share a number. The numbers do not have to be concurrent but it is recommended.

Forward

r.forward()

Will migrate the database forward until every migration has ran, or an error occurs. If an error occurs only the migration that generated the error will fail, the ones preceding it will not be rolled back.

Backward

r.backward()

Will migrate the database backward by one migration.

Migration files

Migration files have three parts, all are optional.

  • description Information about the migration, what it does etc.
  • forward sql or code used to migrate the database forward
  • backward sql or code to undo the migration in forward

You can see the files in the ./migrations directory for examples

Yaml

In the yaml migration files the forward and backward attributes are treated as pure sql that is passed through to pg-promise. Multiple queries can be separated by a semicolon.

description: This is an example migration
forward: >
  alter table foo add column bar text not null
backward: >
  alter table foo drop column bar

In the js migration files the forward and backward exports must be functions that are passed a pg-promise transaction with which they can run queries. This is particularly useful for things like data migrations.

module.exports = {
  description: 'Redcrab Migration',
  forward: db => {
    db.query('insert into foo (bar) values ($1)', ['baz']);
  },
  backward: db => {
    db.query('delete from foo where bar = $1', ['baz']);
  }
};

Concurrency

Database

This library uses advisory locks in order to gain exclusive access to the migrations table and perform its actions. Because they are "application-defined" the lock itself has to be defined by the application, in this case Redcrab. Redcrab uses advisory lock number 72656463726162. This is hopefully a sufficiently unique number that it doesn't collide with any other applications using your database. However, in the unlikely even that it DOES collide you can override this with the advisory_lock option when instantiating Redcrab.

File

Redcrab assumes that it has exclusive access to the filesystem. Specifically to the migrations directory (i.e. no other processes will be adding/removing migration files during its runtime).