2017-02-09 20:00:38 -08:00
2017-02-09 20:00:38 -08:00
2017-02-09 19:42:48 -08:00
2017-02-09 19:42:48 -08:00
2017-02-09 19:52:50 -08:00
2017-02-09 13:47:28 -08:00
2017-02-08 19:54:50 -08:00
2017-02-07 22:01:29 -08:00
2017-02-09 18:23:08 -08:00
2017-02-09 12:03:03 -08:00
2017-02-09 18:23:08 -08:00
2017-02-09 18:19:13 -08:00
2017-02-09 18:26:58 -08:00
2017-02-09 20:00:38 -08:00
2017-02-09 18:16:16 -08:00
2017-02-09 18:19:13 -08:00

migrate

Build Status GoDoc Coverage Status

Database migrations written in Go. Use as CLI or import as library.

go get -u -tags 'postgres' -o migrate github.com/mattes/migrate/cli

import (
  "github.com/mattes/migrate"
  _ "github.com/mattes/migrate/database/postgres"
)

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.

CLI usage

CLI Documentation

Example:

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

Development, Testing and Contributing

  1. Make sure you have a running Docker daemon (Install for MacOS)
  2. Fork this repo and git clone somewhere to $GOPATH/src/github.com/%you%/migrate
  3. make rewrite-import-paths to update imports to your local fork
  4. Confirm tests are working: make test-short
  5. Write awesome code ...
  6. make test to run all tests against all database versions
  7. make restore-import-paths to restore import paths
  8. Push code and open Pull Request

Some more notes:

  • You can specify which database/ source tests to run:
    make test-short SOURCE='file go-bindata' DATABASE='postgres cassandra'
  • After make test, run make html-coverage which opens a shiny test coverage overview.
  • Missing imports? make deps
  • make build-cli builds the CLI in directory cli/build/.
  • make list-external-deps lists all external dependencies for each package
  • make docs && make open-docs opens godoc in your browser, make kill-docs kills the godoc server.
    Repeatedly call make docs to refresh the server.

Alternatives

Description
Database migrations. CLI and Golang library.
Readme MIT
Languages
Go 98.6%
Makefile 1%
Dockerfile 0.3%