commit | 035c07716cd373d88456ec4d701402df52584cb4 | [log] [tgz] |
---|---|---|
author | Matthias Kadenbach <matthias.kadenbach@gmail.com> | Thu May 18 02:37:49 2017 |
committer | GitHub <noreply@github.com> | Thu May 18 02:37:49 2017 |
tree | fe595a09e75e5c6485f2a12c3205904ad7480e9f | |
parent | 1b48b97aa4dfb259de313c3341d2d4672fd95e17 [diff] | |
parent | 0d9689ab9f96e689c6ba91619203778352e9bf76 [diff] |
Merge pull request #231 from mattes/cli-updates build cli with all source and database drivers
Database migrations written in Go. Use as CLI or import as library.
Looking for v1?
Database drivers run migrations. Add a new database?
Source drivers read migrations from local or remote sources. Add a new source?
$ brew install migrate --with-postgres $ migrate -database postgres://localhost:5432/database up 2
GracefulStop chan bool
.io.Reader
streams internally for low memory overhead.import (
"github.com/mattes/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)
}
Want to use an existing database client?
import (
"database/sql"
_ "github.com/lib/pq"
"github.com/mattes/migrate"
"github.com/mattes/migrate/database/postgres"
_ "github.com/mattes/migrate/source/file"
)
func main() {
db, err := sql.Open("postgres", "postgres://localhost:5432/database?sslmode=enable")
driver, err := postgres.WithInstance(db, &postgres.Config{})
m, err := migrate.NewWithDatabaseInstance(
"file:///migrations",
"postgres", driver)
m.Steps(2)
}
Each migration has an up and down migration. Why?
1481574547_create_users_table.up.sql 1481574547_create_users_table.down.sql
Best practices: How to write migrations.
Yes, please! Makefile
is your friend, read the development guide.
Also have a look at the FAQ.
Alternatives
https://bitbucket.org/liamstask/goose, https://github.com/tanel/dbmigrate,
https://github.com/BurntSushi/migration, https://github.com/DavidHuie/gomigrate,
https://github.com/rubenv/sql-migrate