4 releases

Uses old Rust 2015

0.0.4 Oct 7, 2018
0.0.3 Oct 7, 2018
0.0.2 Oct 6, 2018
0.0.1 Oct 6, 2018

#22 in #table-column

MIT license

19KB
401 lines

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.

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

Dependencies

~12–21MB
~300K SLoC