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

pgup

v1.0.0

Published

Small production-ready schema migration tool for postgres

Downloads

33

Readme

pgup

Small schema migration tool for postgres

Short instruction

  • Install library into your project:

    npm i pgup
  • Place your migrations scripts in migrations folder:

    # ./migrations
    
    1-initial.sql
    2-add-some-changes.sql
    ...
  • If you want to make possible to revert version of database version from higher to lower one, you can optionally add .revert.sql scripts:

  # ./migrations

  1-initial.sql
  1-initial.revert.sql
  2-add-some-changes.sql
  2-add-some-changes.revert.sql
  • Now you can run pgup run to run your migrations

    Make sure you provide env variables to connect to the database: PGHOST, PGPORT, PGDATABASE, PGUSER, PGPASSWORD...

    To see all possible connection env configs, visit https://www.postgresql.org/docs/9.1/libpq-envars.html

  • Optionally, you can add migration script to your package.json

    # ./package.json
    # ...
      
    "scripts": {
      
        "migration": "pgup run"
          
    }

Commands

run

pgup run [--dry] [--from=...] [--revert] [--to=...]

Runs a migration. From current (or passed) version of database to last (or passed) version.

Each migration will be done in separate database transaction.

If final version should be lower than current one, you should add --revert param. By default, it fails to migrate to lower version.

Params:

  • --dry - Instructs to not run a migration on a database. Only prints sql to the output.

  • --from - Current version of a db. If not passed, version will be taken from db.

    DON'T PASS IT unless you know what are you doing

  • --to - Version db should be migrated to. If not passed, migration will be done to the latest migration file

  • --revert - Revert db migration (if possible)

Env variables:

  • PGHOST, PGPORT, PGDATABASE, PGUSER, PGPASSWORD - Credentials to your database

    To see all possible connection configs, visit https://www.postgresql.org/docs/9.1/libpq-envars.html

  • PGUP_SCOPE - If you store more then one project in the same database, use this env to pass a unique project name. Actual database version will be stored in table _migration_versions(scope, version) Default scope is default

  • PGUP_MIGRATIONS_PATH - If folder with your <version>.sql files is other than migrations, put its name in this env.

  • PGUP_LOCK - pgup uses advisory db lock to be set to prevent attempts of simultaneous migrations by few pgup app instances during deployment. Default advisory lock is 1012, but you can change its value with this env You can set it to 0, if you want to disable locking feature

db-version

pgup db-version

Shows a current version of a database

The same env vars can be passed, as for "run" command

help

pgup [help]

Shows help info

License

ISC

Copyright 2021 Roman Ditchuk

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.