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

@quave/migrations

v2.0.0

Published

Backend-agnostic migration orchestrator with pluggable adapters

Readme

@quave/migrations

Backend-agnostic migration orchestrator. Install an adapter package alongside this one to pick a backend:

Need a backend we don't ship? Implement the MigrationBackend interface exported from this package and pass it to new Migrations(backend, options).

Install

# Pick the adapter that matches your database. It depends on this package.
npm install @quave/migrations-mongodb
# or
npm install @quave/migrations-postgres
# or
npm install @quave/migrations-redshift

Quick start (MongoDB)

import { MongoClient } from 'mongodb';
import { createMongoMigrations } from '@quave/migrations-mongodb';

const client = await new MongoClient('mongodb://localhost:27017').connect();
const db = client.db('myapp');

const migrations = createMongoMigrations(db, { log: true });

migrations.add({
  version: 1,
  name: 'Create users collection',
  up: async (_m, { db }) => {
    await db.createCollection('users');
    await db.collection('users').createIndex({ email: 1 }, { unique: true });
  },
  down: async (_m, { db }) => {
    await db.collection('users').drop();
  },
});

const result = await migrations.migrateTo('latest');
if (!result.success) {
  throw result.error;
}

Quick start (Redshift)

import { createRedshiftMigrations } from '@quave/migrations-redshift';

const migrations = createRedshiftMigrations({
  database: 'dev',
  workgroupName: 'my-serverless-wg',   // or clusterIdentifier + dbUser/secretArn
  region: 'us-east-1',
});

migrations.add({
  version: 1,
  name: 'Create events table',
  up: async (_m, { execute }) => {
    await execute('CREATE TABLE events (id BIGINT IDENTITY, payload VARCHAR(4000));');
  },
});

await migrations.migrateTo('latest');

Commands

  • migrateTo('latest') — run all pending migrations.
  • migrateTo(5) — run up (or down) to a specific version.
  • migrateTo('3,rerun') — rerun a single version's up.
  • migrateTo('latest,exit') — migrate then process.exit(0) (script mode).
  • getVersion() — current recorded version.
  • unlock() — release a stuck lock after a crash.
  • reset() — test-only: wipe persisted state.

Distributed locking

Every adapter's tryLock() is enforced by the database, so concurrent migration processes are safe:

  • MongoDB: atomic updateOne({_id:'control', locked:false}, ...). The DB guarantees exactly one winner.
  • Postgres: conditional UPDATE ... WHERE locked = FALSE RETURNING id. Postgres's row-level lock under READ COMMITTED guarantees the second caller sees locked = TRUE and matches zero rows.
  • Redshift: single-row serializable UPDATE ... WHERE locked = FALSE with a client-generated nonce, then a read-back SELECT to confirm ownership. Serialization failures (SQLSTATE 40001 / "Serializable isolation violation") are caught and treated as "did not win."

Writing a custom backend

import { Migrations, MigrationBackend, ControlState } from '@quave/migrations';

interface MyCtx { /* whatever your migrations need */ }

class MyBackend implements MigrationBackend<MyCtx> {
  async init() { /* create control table/doc if missing */ }
  async getControl(): Promise<ControlState> { /* return {version, locked} */ }
  async tryLock(): Promise<boolean> { /* atomic false -> true, return true iff won */ }
  async unlock(): Promise<void> { /* unconditional release */ }
  async setVersion(version: number): Promise<void> { /* persist */ }
  getContext(): MyCtx { /* passed to user up/down */ }
  async reset(): Promise<void> { /* test-only wipe */ }
}

The @quave/migrations/testing subpath exports runBackendContract(name, makeBackend) — a jest suite every backend should pass.

API surface

  • Migrations<TContext> class
  • MigrationBackend<TContext> interface + ControlState
  • Migration<TContext>, MigrationOptions, MigrationResult types
  • Logger, LoggerFunction, LoggerOptions
  • @quave/migrations/testing: FakeBackend, createFakeBackend, runBackendContract

License

MIT