All Projects → sastraxi → Pgsh

sastraxi / Pgsh

Licence: mit
Branch your PostgreSQL Database like Git

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Pgsh

Sqlboiler
Generate a Go ORM tailored to your database schema.
Stars: ✭ 4,497 (+950.7%)
Mutual labels:  postgresql
Shmig
Database migration tool written in BASH.
Stars: ✭ 408 (-4.67%)
Mutual labels:  postgresql
Zhparser
zhparser is a PostgreSQL extension for full-text search of Chinese language
Stars: ✭ 418 (-2.34%)
Mutual labels:  postgresql
Python Dotenv
Get and set values in your .env file in local and production servers. 🎉
Stars: ✭ 4,533 (+959.11%)
Mutual labels:  dotenv
Patroni
A template for PostgreSQL High Availability with Etcd, Consul, ZooKeeper, or Kubernetes
Stars: ✭ 4,434 (+935.98%)
Mutual labels:  postgresql
Web
适合java新手入门练习的java web个人网站项目,目前主要维护web-mysql和web-psql两个分支。前台包括博客、代码库、文件下载、留言、登录注册、站内搜索、分类目录等功能,后台包括上传文件、博客、代码,编辑、删除文章,修改个人资料等功能,目前暂停开发新功能。网址:https://demo.hemingsheng.cn ,觉得不错的欢迎 star。 手机版网址:
Stars: ✭ 414 (-3.27%)
Mutual labels:  postgresql
Diwata
A user-friendly database interface
Stars: ✭ 386 (-9.81%)
Mutual labels:  postgresql
Sqlprovider
A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
Stars: ✭ 423 (-1.17%)
Mutual labels:  postgresql
Dbdot
Generate DOT description for postgres db schema
Stars: ✭ 406 (-5.14%)
Mutual labels:  postgresql
Smf2.1
Thoughts, Ideas and bits of code for SMF (2.1)
Stars: ✭ 416 (-2.8%)
Mutual labels:  postgresql
Sync Dotenv
Keep your .env in sync with .env.example
Stars: ✭ 393 (-8.18%)
Mutual labels:  dotenv
Micronaut Microservices Poc
Very simplified insurance sales system made in a microservices architecture using Micronaut
Stars: ✭ 394 (-7.94%)
Mutual labels:  postgresql
Rum
RUM access method - inverted index with additional information in posting lists
Stars: ✭ 414 (-3.27%)
Mutual labels:  postgresql
Sysbench
Scriptable database and system performance benchmark
Stars: ✭ 4,268 (+897.2%)
Mutual labels:  postgresql
Doctrine Json Odm
An object document mapper for Doctrine ORM using JSON types of modern RDBMS.
Stars: ✭ 420 (-1.87%)
Mutual labels:  postgresql
Django React Boilerplate
DIY Django + React Boilerplate for starting your SaaS
Stars: ✭ 385 (-10.05%)
Mutual labels:  postgresql
With advisory lock
Advisory locking for ActiveRecord
Stars: ✭ 409 (-4.44%)
Mutual labels:  postgresql
Antdata.orm
特色:vs插件或者t4一键生成entity 支持配置非物理外键。分离linq转sql引擎(原生linq非扩展)和执行dal功能,支持异步,支持netcore2.0
Stars: ✭ 428 (+0%)
Mutual labels:  postgresql
Airship
Secure Content Management for the Modern Web - "The sky is only the beginning"
Stars: ✭ 422 (-1.4%)
Mutual labels:  postgresql
Hasql
Performant PostgreSQL driver with a flexible mapping API
Stars: ✭ 415 (-3.04%)
Mutual labels:  postgresql

pgsh: PostgreSQL tools for local development

npm license circleci downloads

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:

  • your project reads its database configuration from the environment
  • it uses a .env file to do so in development.

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

Language / Framework .env solution Maturity
javascript dotenv high

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):

  • url (default) when one variable in your .env has your full database connection string (e.g. DATABASE_URL=postgres://...)
  • split when your .env has different keys (e.g. PG_HOST=localhost, PG_DATABASE=myapp, ...)

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

  • pgsh init generates a .pgshrc file for your project.
  • pgsh url prints your connection string.
  • pgsh psql <name?> -- <psql-options...?> connects to the current (or named) database with psql
  • pgsh current prints the name of the database that your connection string refers to right now.
  • pgsh or pgsh list <filter?> prints all databases, filtered by an optional filter. Output is similar to git branch. By adding the -a option you can see migration status too!

Database branching

Read up on the recommended branching model for more details.

  • pgsh clone <from?> <name> clones your current (or the from) database as name, then (optionally) runs switch <name>.
  • pgsh create <name> creates an empty database, then runs switch <name> and optionally migrates it to the latest version.
  • pgsh switch <name> makes name your current database, changing the connection string.
  • pgsh destroy <name> destroys the given database. This cannot be undone. You can maintain a blacklist of databases to protect from this command in .pgshrc

Dump and restore

  • pgsh dump <name?> dumps the current database (or the named one if given) to stdout
  • pgsh restore <name> restores a previously-dumped database as name from stdin

Migration management (via knex)

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

  • pgsh up migrates the current database to the latest version found in your migration directory.

  • pgsh down <version> down-migrates the current database to version. Requires your migrations to have down edges!

  • pgsh force-up re-writes the knex_migrations table entirely based on your migration directory. In effect, running this command is saying to knex "trust me, the database has the structure you expect".

  • pgsh force-down <version> re-writes the knex_migrations table to not include the record of any migration past the given version. Use this command when you manually un-migrated some migations (e.g. a bad migration or when you are trying to undo a migration with missing "down sql").

  • pgsh validate compares the knex_migrations table to the configured migrations directory and reports any inconsistencies between the two.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].