mirror of https://github.com/status-im/migrate.git
526c0a918e | ||
---|---|---|
cli | ||
database | ||
migrate | ||
source | ||
testing | ||
.gitignore | ||
.travis.yml | ||
CONTRIBUTING.md | ||
LICENSE | ||
Makefile | ||
README.md | ||
log.go | ||
migrate.go | ||
migrate_test.go | ||
migration.go | ||
migration_test.go | ||
util.go | ||
util_test.go |
README.md
migrate
Database migrations written in Go. Use as CLI or import as library.
Databases
Database drivers are responsible for applying migrations to databases. Implementing a new database driver is easy. Just implement database/driver interface
Migration Sources
Source Drivers read migrations from various locations. Implementing a new source driver is easy. Just implement the source/driver interface.
- Filesystem - read from fileystem (always included)
- Go-Bindata - read from embedded binary data (jteeuwen/go-bindata)
- Github - read from remote Github repositories
- AWS S3 - read from Amazon Web Services S3
- Google Cloud Storage - read from Google Cloud Platform Storage
CLI usage
Example:
go get -u -tags 'postgres' -o migrate github.com/mattes/migrate/cli
migrate -database postgres://localhost:5432/database up 2
Use in your Go project
import (
"github.com/mattes/migrate/migrate"
_ "github.com/mattes/migrate/database/postgres"
_ "github.com/mattes/migrate/source/github"
)
func main() {
m, err := migrate.New("github://mattes:personal-access-token@mattes/migrate_test",
"postgres://localhost:5432/database?sslmode=enable")
m.Steps(2)
}
Migration files
Each migration version has an up and down migration.
1481574547_create_users_table.up.sql
1481574547_create_users_table.down.sql