A simple PostgreSQL data migration tool
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
Cargo.lock
Cargo.toml
LICENSE
README.md

README.md

Pig 🐷

This tool was created to simplify working with PostgreSQL for every day db tasks for personal projects. Common tasks like creating simple migrations, applying them incrementally on multiple servers, and seeing what's in a database should be easy to do.

Install

cargo install pig

What problem does this solve?

Most of the time when working with SQL databases for personal projects, I'm only doing a few things. Managing tables in basic ways and applying those changes to one or more servers. These changes can been seen as a date ordered sequence of SQL files to execute on your database. Pig stores what latest file has been applied on your db so next time you apply the migrations, it only executes the newest ones in order. I added a few helper utilities for quickly adding common SQL commands to your current editing migration. You may face other challenges with migrations in real world projects, but this tool might offer you a quick way to get going with SQL and having fun.

Example Usage

export PIG_CONNECTION_STRING="<your secret connection string>"

# Create a migration
pig create "My first migration"
# Add SQL to apply/revert people table to latest migration
pig modify create-table people     
# Add SQL to apply/revert name column to latest migration
pig modify add-column people name TEXT
# See whats going to be applied
pig plan                        
# Apply migrations in current directory
pig apply    
# See people table on db
pig show tables
# See people table's columns
pig show table people                       
# Should see nothing to apply
pig plan  
# Create new migration for dropping people
pig create "Drop people"       
# Add drop table command
pig modify drop-table people  
# Should only see one migration to apply
pig plan   
# Apply only the newest migration
pig apply
# Now people table is removed from db
pig show tables