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

@spokedev/puzzler

v1.3.11

Published

A simple db migration manager

Downloads

31

Readme

Puzzler By Jigsaw

Puzzler is a low configuration, stateful migration manager for Node.js.

Installation

npm install @spokedev/puzzler --save-dev;

Core Terminology

Transaction => A single up/down pair of actions to take.
Migrate => Run a set of up transactions.
Rollback => Run a set of down transactions.

Configuration

Puzzler expects database credentials to be provided via config file:

config.js:

module.exports = {
  database: {
    name: 'database name',
    host: 'localhost',
    port: 26257,
    user: 'root',
    password: 'unsecurepassword',
    pool_size: { min: 0, max: 1 }
  }
};

State Management

Puzzler will create a migrations history table in your db which contains the history of every migration carried out. This is used to track the current state of the db, and ensure the correct migrations are carried out.

CLI

Puzzler supports three actions.

Make

Creates a new template migration file in target directory, with given name.

./node_modules/bin/puzzler make --transactionDir=<transactionDir> --migrationName=addClientTable

[REQUIRED] transactionDir => The location to put the new transaction template.
[OPTIONAL] migrationName => The name to give to the new transaction. Defaults to migration.

Migrate

Carries out up migrations in timestamp order.

./node_modules/bin/puzzler migrate --transactionDir=<transactionDir> --config=config.js --partial=1

[REQUIRED] transactionDir => The location to source transactions from.
[REQUIRED] config => The location of config file (see Configuration).
[OPTIONAL] partial => Option to carry out a specified number of up transactions. Defaults to 0 (i.e. run all migrations).

Rollback

Carries out down rollbacks in timestamp order.

./node_modules/bin/puzzler rollback --transactionDir=<transactionDir> --config=config.js --partial=1

[REQUIRED] transactionDir => The location to source transactions from.
[REQUIRED] config => The location of config file (see Configuration).
[OPTIONAL] partial => Option to carry out a specified number of up transactions. Defaults to 0 (i.e. run all migrations).

Module

Puzzler can be used as part of a wider codebase by requiring the module. When used this way it expects to be provided a knex.js connection pool:

const puzzler = require('@spokedev/puzzler');
const knex = require('knex');

const pool = knex({
  client: 'pg',
  version: '0.0',
  connection: {
    user: 'user',
    password: 'password',
    host: 'localhost',
    database: 'databaseName',
    port: 2567
  },
  pool: { min: 0, max: 1 }
});

// make a new transaction
puzzler.make({
  transactionDir: `${__dirname}/transactions`,
  migrationName: 'addClientsTable'
});

// run all migrations
puzzler.migrate({         
  transactionDir: `${__dirname}/transactions`,
  pool: pool,
  partial: 0 
});

// rollback all migrations
puzzler.rollback({         
  transactionDir: `${__dirname}/transactions`,
  pool: pool,
  partial: 0 
});