Database migrations. CLI and Golang library.
Go to file
mattes f2f03998ae fix renamed Read() func in test 2014-08-13 01:44:39 +02:00
driver improve postgres errors and error formatting in general 2014-08-13 01:43:34 +02:00
file fix renamed Read() func in test 2014-08-13 01:44:39 +02:00
migrate Use channels for communication 2014-08-12 21:17:31 +02:00
pipe Use channels for communication 2014-08-12 21:17:31 +02:00
.gitignore initial 2014-08-11 03:42:57 +02:00
.travis.yml update travis to run tests not in parallel 2014-08-11 03:57:29 +02:00
README.md add godoc badge 2014-08-11 05:06:38 +02:00
main.go improve postgres errors and error formatting in general 2014-08-13 01:43:34 +02:00

README.md

migrate

Build Status GoDoc

migrate can be used as CLI or can be imported into your existing Go code.

Available Drivers

Need another driver? Just implement the Driver interface and open a PR.

Usage from Terminal

# install
go get github.com/mattes/migrate

# create new migration
migrate -url postgres://user@host:port/database -path ./db/migrations create add_field_to_table

# apply all *up* migrations
migrate -url postgres://user@host:port/database -path ./db/migrations up

# apply all *down* migrations
migrate -url postgres://user@host:port/database -path ./db/migrations down

# roll back the most recently applied migration, then run it again.
migrate -url postgres://user@host:port/database -path ./db/migrations redo

# down and up again
migrate -url postgres://user@host:port/database -path ./db/migrations reset

# show current migration version
migrate -url postgres://user@host:port/database -path ./db/migrations version

# apply the next n migrations
migrate -url postgres://user@host:port/database -path ./db/migrations migrate +1
migrate -url postgres://user@host:port/database -path ./db/migrations migrate +2
migrate -url postgres://user@host:port/database -path ./db/migrations migrate +n

# apply the *down* migration of the current version 
# and the previous n-1 migrations
migrate -url postgres://user@host:port/database -path ./db/migrations migrate -1
migrate -url postgres://user@host:port/database -path ./db/migrations migrate -2
migrate -url postgres://user@host:port/database -path ./db/migrations migrate -n

Usage from within Go

See http://godoc.org/github.com/mattes/migrate/migrate

import "github.com/mattes/migrate/migrate"


migrate.Up("postgres://user@host:port/database", "./db/migrations")
// ... 
// ... 

Migrations format

./db/migrations/001_initial.up.sql
./db/migrations/001_initial.down.sql

Why two files? This way you could do sth like psql -f ./db/migrations/001_initial.up.sql.

Credits