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

pg-migration-promise

v1.0.0

Published

pg database migration tool built with a promise interface

Downloads

1

Readme

pg-migration

A Node.js package to help with database migrations -- that is, changes to your database over time.

The high level idea is to bring your projects' database up to the latest version in an automatic, consistent manor across many environments (development, staging and production).

Status

This project is ready for consumption. For now, you can include it in your project via npm's git integration. More information here: https://docs.npmjs.com/files/package.json#github-urls

I'll be deploying a npm package once I feel no further refinements are needed.

Examples

A basic example is provided below. This product is intended to aid keeping several developers database instances up to date no matter which version is pulled from source control. Do note, however, that this product doesn't support going backwards -- only forwards.

API Documentation

The full API Documentation can be found at https://frankv01.github.io/pg-migration/

A quick summary is follows.

Migration Object

The migration object is a JSON element that contains your SQL to create and modify the definition of the database. Basic structure is this:

{
  "1.0.0": {
    "tables": ["CREATE TABLE ..."],
    "data": ["INSERT ..."],
    "indexes": []
  },
  "1.0.1": {
    "tables": ["DROP TABLE ..."],
    "data": ["UPDATE"],
    "indexes": []
  }
}

With node, you can define a .json file and require it to a variable or directly in the object's construction.

App Initialization

After the migration object is setup, preferably in a different module, you execute code such as the following in a bootstrap or start up module. Where, exactly, is up to you as long as it's prior to database access by your application.

pg-migration returns a promise so you can perform steps after with then or handle errors which can result from bad SQL or, lets face it, a package bug.

const pg_migration = require('pg-migration');
const d = pg_migration({
  connection: 'postgres://john:123@localhost:5432/products', //or an object 
  migrations: require('migrations.json')
});
d.catch(function(er) {
  console.log('pg-migration: Error occurred during pg-migration', er);
});

Contributions

All contributions are welcomed. First time contributes are especially encouraged as this is a new, relatively simple project with straight forward requirements. If you want to break into Node JS, this is a good project.

I am open to suggestions as well; Node is not my "day time forte" but has quickly become a technology of interest. That said, I'm trying to take queues from Nightwatch and pg-promise and am -- at a high level -- following those ideas amongst my own.

Setup

The following is instructions to set up this project on your workstations for hacking/exploration or for contributions. The intention is to get the dependencies installed so that you can run the unit tests. Unit tests are good

Dependencies

There are few dependencies that you must manually install. Node.js and postgres.

Please install these via your method of choice.

  • Node
    • Windows: Use installer from the web site
    • Mac OS X: Use the installer or the Linux method
    • Linux: I'd suggest using nvm
  • Postgres

Get the source

First, clone the project with your tool of choice. I can't cover all tools so I'll provide instructions with the git cli.

cd ~/github #or where you keep you github/git repos
git clone https://github.com/FrankV01/pg-migration.git
cd pg-migration
npm install

Assuming the above commands all execute successfully, the following should pass 100%; Run the following:

npm test

And you should get results similar to the following. The these results were trimmed:

[...]
index
    ✓ no arguments throws exception
    ✓ missing migration argument
    ✓ missing connection argument
    ✓ calls dbMigrate with options; returns a promise


  17 passing (2s)

Wiki

Please see the wiki for more information: https://github.com/FrankV01/pg-migration/wiki