migrate/README.md

91 lines
2.5 KiB
Markdown
Raw Normal View History

2014-08-11 01:42:57 +00:00
# migrate
2017-02-08 06:40:45 +00:00
[![Build Status](https://travis-ci.org/mattes/migrate.svg?branch=v3.0-prev)](https://travis-ci.org/mattes/migrate)
2014-08-11 03:06:38 +00:00
[![GoDoc](https://godoc.org/github.com/mattes/migrate?status.svg)](https://godoc.org/github.com/mattes/migrate)
2017-02-09 00:17:04 +00:00
[![Coverage Status](https://coveralls.io/repos/github/mattes/migrate/badge.svg?branch=v3.0-prev)](https://coveralls.io/github/mattes/migrate?branch=v3.0-prev)
2014-08-11 03:06:38 +00:00
2017-02-10 04:07:04 +00:00
__Database migrations written in Go. Use as CLI or import as library.__
2014-08-13 21:58:30 +00:00
2014-08-11 01:42:57 +00:00
2017-02-08 06:40:45 +00:00
## Databases
2014-08-11 01:42:57 +00:00
2017-02-08 06:40:45 +00:00
Database drivers are responsible for applying migrations to databases.
Implementing a new database driver is easy. Just implement [database/driver interface](database/driver.go)
2014-08-11 01:42:57 +00:00
2017-02-08 06:40:45 +00:00
* [PostgreSQL](database/postgres)
* [Cassandra](database/cassandra)
* [SQLite](database/sqlite)
* [MySQL/ MariaDB](database/mysql)
* [Neo4j](database/neo4j)
* [Ql](database/ql)
* [MongoDB](database/mongodb)
* [CrateDB](database/crate)
* [Shell](database/shell)
2014-08-11 01:42:57 +00:00
2017-02-08 06:40:45 +00:00
## Migration Sources
2014-08-11 01:42:57 +00:00
2017-02-08 06:40:45 +00:00
Source Drivers read migrations from various locations. Implementing a new source driver
is easy. Just implement the [source/driver interface](source/driver.go).
2014-08-11 01:42:57 +00:00
2017-02-08 06:40:45 +00:00
* [Filesystem](source/file) - read from fileystem (always included)
* [Go-Bindata](source/go-bindata) - read from embedded binary data ([jteeuwen/go-bindata](https://github.com/jteeuwen/go-bindata))
* [Github](source/github) - read from remote Github repositories
* [AWS S3](source/aws-s3) - read from Amazon Web Services S3
* [Google Cloud Storage](source/google-cloud-storage) - read from Google Cloud Platform Storage
2014-08-11 01:42:57 +00:00
2017-02-08 06:40:45 +00:00
## CLI usage
2014-08-13 00:38:29 +00:00
2017-02-10 04:00:38 +00:00
__[CLI Documentation](cli/README.md)__
Example:
```
2017-02-10 04:07:04 +00:00
go get -u -tags 'postgres' -o migrate github.com/mattes/migrate/cli
2017-02-08 06:40:45 +00:00
migrate -database postgres://localhost:5432/database up 2
2014-08-11 01:42:57 +00:00
```
2017-02-08 06:40:45 +00:00
## Use in your Go project
2014-08-11 01:42:57 +00:00
2014-08-13 00:38:29 +00:00
```go
2017-02-08 06:40:45 +00:00
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)
2014-08-13 00:38:29 +00:00
}
2014-08-11 01:42:57 +00:00
```
2014-08-13 02:04:58 +00:00
## Migration files
2014-08-13 00:38:29 +00:00
2017-02-08 06:40:45 +00:00
Each migration version has an up and down migration.
2014-08-11 01:42:57 +00:00
```
2017-02-08 06:40:45 +00:00
1481574547_create_users_table.up.sql
1481574547_create_users_table.down.sql
2014-08-11 01:42:57 +00:00
```
## Development, Testing and Contributing
2017-02-10 04:03:56 +00:00
__[Guide](CONTRIBUTING.md)__
2014-08-11 01:42:57 +00:00
2014-08-13 12:06:02 +00:00
## Alternatives
2014-08-11 01:42:57 +00:00
2014-08-13 00:38:29 +00:00
* https://bitbucket.org/liamstask/goose
2014-08-15 00:35:23 +00:00
* https://github.com/tanel/dbmigrate
* https://github.com/BurntSushi/migration
2014-08-15 11:51:04 +00:00
* https://github.com/DavidHuie/gomigrate
* https://github.com/rubenv/sql-migrate
2014-08-13 00:38:29 +00:00