github.com/yuukihogo/migrate@v3.0.0+incompatible/README.md (about) 1 [![Build Status](https://travis-ci.org/mattes/migrate.svg?branch=v3.0-prev)](https://travis-ci.org/mattes/migrate) 2 [![GoDoc](https://godoc.org/github.com/mattes/migrate?status.svg)](https://godoc.org/github.com/mattes/migrate) 3 [![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) 4 [![packagecloud.io](https://img.shields.io/badge/deb-packagecloud.io-844fec.svg)](https://packagecloud.io/mattes/migrate?filter=debs) 5 6 # migrate 7 8 __Database migrations written in Go. Use as [CLI](#cli-usage) or import as [library](#use-in-your-go-project).__ 9 10 * Migrate reads migrations from [sources](#migration-sources) 11 and applies them in correct order to a [database](#databases). 12 * Drivers are "dumb", migrate glues everything together and makes sure the logic is bulletproof. 13 (Keeps the drivers lightweight, too.) 14 * Database drivers don't assume things or try to correct user input. When in doubt, fail. 15 16 17 Looking for [v1](https://github.com/mattes/migrate/tree/v1)? 18 19 20 ## Databases 21 22 Database drivers run migrations. [Add a new database?](database/driver.go) 23 24 * [PostgreSQL](database/postgres) 25 * [Cassandra](database/cassandra) ([todo #164](https://github.com/mattes/migrate/issues/164)) 26 * [SQLite](database/sqlite) ([todo #165](https://github.com/mattes/migrate/issues/165)) 27 * [MySQL/ MariaDB](database/mysql) 28 * [Neo4j](database/neo4j) ([todo #167](https://github.com/mattes/migrate/issues/167)) 29 * [Ql](database/ql) ([todo #168](https://github.com/mattes/migrate/issues/168)) 30 * [MongoDB](database/mongodb) ([todo #169](https://github.com/mattes/migrate/issues/169)) 31 * [CrateDB](database/crate) ([todo #170](https://github.com/mattes/migrate/issues/170)) 32 * [Shell](database/shell) ([todo #171](https://github.com/mattes/migrate/issues/171)) 33 * [Google Cloud Spanner](database/spanner) ([todo #172](https://github.com/mattes/migrate/issues/172)) 34 35 36 37 ## Migration Sources 38 39 Source drivers read migrations from local or remote sources. [Add a new source?](source/driver.go) 40 41 * [Filesystem](source/file) - read from fileystem (always included) 42 * [Go-Bindata](source/go-bindata) - read from embedded binary data ([jteeuwen/go-bindata](https://github.com/jteeuwen/go-bindata)) 43 * [Github](source/github) - read from remote Github repositories 44 * [AWS S3](source/aws-s3) - read from Amazon Web Services S3 ([todo #162](https://github.com/mattes/migrate/issues/162)) 45 * [Google Cloud Storage](source/google-cloud-storage) - read from Google Cloud Platform Storage ([todo #163](https://github.com/mattes/migrate/issues/163)) 46 47 48 49 ## CLI usage 50 51 * Simple wrapper around this library. 52 * Handles ctrl+c (SIGINT) gracefully. 53 * No config search paths, no config files, no magic ENV var injections. 54 55 __[CLI Documentation](cli)__ 56 57 ([brew todo #156](https://github.com/mattes/migrate/issues/156)) 58 59 ``` 60 $ brew install migrate --with-postgres 61 $ migrate -database postgres://localhost:5432/database up 2 62 ``` 63 64 65 ## Use in your Go project 66 67 * API is stable and frozen for this release (v3.x). 68 * Package migrate has no external dependencies. 69 * Only import the drivers you need. 70 (check [dependency_tree.txt](https://github.com/mattes/migrate/releases) for each driver) 71 * To help prevent database corruptions, it supports graceful stops via `GracefulStop chan bool`. 72 * Bring your own logger. 73 * Uses `io.Reader` streams internally for low memory overhead. 74 * Thread-safe and no goroutine leaks. 75 76 __[Go Documentation](https://godoc.org/github.com/mattes/migrate)__ 77 78 ```go 79 import ( 80 "github.com/mattes/migrate" 81 _ "github.com/mattes/migrate/database/postgres" 82 _ "github.com/mattes/migrate/source/github" 83 ) 84 85 func main() { 86 m, err := migrate.New( 87 "github://mattes:personal-access-token@mattes/migrate_test", 88 "postgres://localhost:5432/database?sslmode=enable") 89 m.Steps(2) 90 } 91 ``` 92 93 Want to use an existing database client? 94 95 ```go 96 import ( 97 "database/sql" 98 _ "github.com/lib/pq" 99 "github.com/mattes/migrate" 100 "github.com/mattes/migrate/database/postgres" 101 ) 102 103 func main() { 104 db, err := sql.Open("postgres", "postgres://localhost:5432/database?sslmode=enable") 105 driver, err := postgres.WithInstance(db, &postgres.Config{}) 106 m, err := migrate.NewWithDatabaseInstance( 107 "file:///migrations", 108 "postgres", driver) 109 m.Steps(2) 110 } 111 ``` 112 113 ## Migration files 114 115 Each migration has an up and down migration. [Why?](FAQ.md#why-two-separate-files-up-and-down-for-a-migration) 116 117 ``` 118 1481574547_create_users_table.up.sql 119 1481574547_create_users_table.down.sql 120 ``` 121 122 [Best practices: How to write migrations.](MIGRATIONS.md) 123 124 125 126 ## Development and Contributing 127 128 Yes, please! [`Makefile`](Makefile) is your friend, 129 read the [development guide](CONTRIBUTING.md). 130 131 Also have a look at the [FAQ](FAQ.md). 132 133 134 135 --- 136 137 __Alternatives__ 138 139 https://bitbucket.org/liamstask/goose, https://github.com/tanel/dbmigrate, 140 https://github.com/BurntSushi/migration, https://github.com/DavidHuie/gomigrate, 141 https://github.com/rubenv/sql-migrate