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