Dead simple tool for running migrations for postgresql.
Supply a DSN to a database and a folder of .[up|down].sql files and run the up command. The down command unmigrates one migration at the time.
This tool does not prevent you from shooting yourself in the foot, it only executes the SQL you provide it with and saves a log to be able to undo work.
Motivation behind the tool is to have a slim docker image to be able to easily run migrations using docker-compose in other projects. And also build new images from the image that contains the migrations for running manually in other environments i.e. prod.
$ go get -u github.com/walle/pgm
$ go install
, $ go build
or $ make pgm
Run all migrations
$ docker run -v /my/migrations:/mymigrations --link mydb walle/pgm -dsn 'postgres://postgres:@mydb/postgres?sslmode=disable' -dir mymigrations up
Undo the latest migration
$ docker run -v /my/migrations:/mymigrations --link mydb walle/pgm -dsn 'postgres://postgres:@mydb/postgres?sslmode=disable' -dir mymigrations down
version: '2'
services:
db:
restart: always
image: postgres
ports:
- "5432:5432"
migrations:
image: walle/pgm
command: -dsn 'postgres://postgres:@db/postgres?sslmode=disable' up
volumes:
- "./sql:/sql"
links:
- db
depends_on:
- db
The only dependency is pq.
$ pgm -dsn postgres://postgres:@localhost/postgres?sslmode=disable -dir ./sql up
Please read CONTRIBUTING.md for more information.
We use Semantic Versioning for versioning. For the versions available, see the tags on this repository.
- Fredrik Wallgren - https://github.com/walle
This project is licensed under the MIT License - see the LICENSE file for details.