Home

Awesome

pgsh: PostgreSQL tools for local development

npm license circleci downloads

<p align="center"> <img src="docs/pgsh-intro-620.gif"> </p>

Finding database migrations painful to work with? Switching contexts a chore? Pull requests piling up? pgsh helps by managing a connection string in your .env file and allows you to branch your database just like you branch with git.


Prerequisites

There are only a couple requirements:

See dotenv for more details, and The Twelve-Factor App for why this is a best practice.

Language / Framework.env solutionMaturity
javascriptdotenvhigh

pgsh can help even more if you use knex for migrations.

Installation

  1. yarn global add pgsh to make the pgsh command available everywhere
  2. pgsh init to create a .pgshrc config file in your project folder, beside your .env file (see src/pgshrc/default.js for futher configuration)
  3. You can now run pgsh anywhere in your project directory (try pgsh -a!)
  4. It is recommended to check your .pgshrc into version control. Why?

URL vs split mode

There are two different ways pgsh can help you manage your current connection (mode in .pgshrc):

Running tests

  1. Make sure the postgres client and its associated tools (psql, pg_dump, etc.) are installed locally
  2. cp .env.example .env
  3. docker-compose up -d
  4. Run the test suite using yarn test. Note that this test suite will destroy all databases on the connected postgres server, so it will force you to send a certain environment variable to confirm this is ok.

Command reference

Database branching

Read up on the recommended branching model for more details.

Dump and restore

Migration management (via knex)

pgsh provides a slightly-more-user-friendly interface to knex's migration system.