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-migrations

v0.1.0

Published

Postgres database migration utility

Downloads

26

Readme

Postgres Migrations

The purpose of this library is to provide liquibase like migration capabilities as a node module and command line interface.

Installation

npm install --global pg-migrations

Why?

liquibase provides many ways of managing migrations including xml, json, yaml, and sql formats for multiple database engines. However, these options can add to complexity, and unfortunately requires java to run.

The purpose of pg-migrations is to provide a simpler way (with fewer options) for managing postgresql database migrations without requiring java.

How it works

pg-migrations works with either a schema configuration file (either yaml, or json), or a directory.

Schema configuration file

The schema configuration file lists all the files to execute as part of the migration. Files can be defined as glob expressions and files matching the glob expression are executed in alpha numeric order (i.e. 1 < 2 < 10).

Example schema configuration file (example/database/schema.yml):

files:
  - '**/*.sql'

Directory

When a directory is used as an input to the migration, it effectively uses the same configuration as provided above (i.e. executes all sql files in the directory in alpha numeric order).

Migration file format

A migration file must start with --migration on the first line and contains one or many changesets (sql statements) preceded by a --changeset comment.

Changeset comment format

A changeset comment takes the following format:

--changeset [changeset name] [type:<once|always|change>] [context:<comma,separated,list>]

Where:

  • changeset name - (optional) name of the changeset, must be unique within the file
  • type - (optional) execution type of the changeset, must be either execute once, always, or on change
    • defaults to once
    • note that a once migration script cannot be modified after it has already been executed (will result in an error on subsequent migrations)
  • context - (optional) list of contexts that the changeset should be executed under
    • default behaviour is to execute under all contexts
    • context is specified using the --context command line argument, the omission of the --context argument implies all contexts will be executed

Example:

--migration
--changeset create table
create table my_table (
  val text
);

--changeset test data context:test
insert into my_table (val)
values ('test data');

Usage

  Usage: pg-migration <schema file|directory> [options]

  Database migration tool for postgres databases

  Options:

    -h, --help                            output usage information
    -V, --version                         output the version number
    -c, --connection <connection string>  database connection string (required)
    -u, --user <user>                     database user name
    -p, --password <password>             database password
    -P, --prompt-password                 prompt for database password
    -s, --generate-script                 output sql script instead of executing the migration
    --context [contexts]                  changeset contexts to execute

Example

pg-migration database/schema.yml -c postgres://postgres@localhost/postgres -p password