github.com/mrqzzz/migrate@v5.1.7+incompatible/README.md (about) 1 [![Build Status](https://img.shields.io/travis/com/golang-migrate/migrate/master.svg)](https://travis-ci.com/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 [![Docker Pulls](https://img.shields.io/docker/pulls/migrate/migrate.svg)](https://hub.docker.com/r/migrate/migrate/) 6 ![Supported Go Versions](https://img.shields.io/badge/Go-1.10%2C%201.11-lightgrey.svg) 7 [![GitHub Release](https://img.shields.io/github/release/golang-migrate/migrate.svg)](https://github.com/golang-migrate/migrate/releases) 8 9 10 # migrate 11 12 __Database migrations written in Go. Use as [CLI](#cli-usage) or import as [library](#use-in-your-go-project).__ 13 14 * Migrate reads migrations from [sources](#migration-sources) 15 and applies them in correct order to a [database](#databases). 16 * Drivers are "dumb", migrate glues everything together and makes sure the logic is bulletproof. 17 (Keeps the drivers lightweight, too.) 18 * Database drivers don't assume things or try to correct user input. When in doubt, fail. 19 20 Forked from [mattes/migrate](https://github.com/mattes/migrate) 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) 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 ### Database URLs 41 42 Database connection strings are specified via URLs. The URL format is driver dependent but generally has the form: `dbdriver://username:password@host:port/dbname?option1=true&option2=false` 43 44 Any [reserved URL characters](https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_reserved_characters) need to be escaped. Note, the `%` character also [needs to be escaped](https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_the_percent_character) 45 46 Explicitly, the following characters need to be escaped: 47 `!`, `#`, `$`, `%`, `&`, `'`, `(`, `)`, `*`, `+`, `,`, `/`, `:`, `;`, `=`, `?`, `@`, `[`, `]` 48 49 It's easiest to always run the URL parts of your DB connection URL (e.g. username, password, etc) through an URL encoder. See the example Python snippets below: 50 ```bash 51 $ python3 -c 'import urllib.parse; print(urllib.parse.quote(input("String to encode: "), ""))' 52 String to encode: FAKEpassword!#$%&'()*+,/:;=?@[] 53 FAKEpassword%21%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D 54 $ python2 -c 'import urllib; print urllib.quote(raw_input("String to encode: "), "")' 55 String to encode: FAKEpassword!#$%&'()*+,/:;=?@[] 56 FAKEpassword%21%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D 57 $ 58 ``` 59 60 ## Migration Sources 61 62 Source drivers read migrations from local or remote sources. [Add a new source?](source/driver.go) 63 64 * [Filesystem](source/file) - read from fileystem 65 * [Go-Bindata](source/go_bindata) - read from embedded binary data ([jteeuwen/go-bindata](https://github.com/jteeuwen/go-bindata)) 66 * [Github](source/github) - read from remote Github repositories 67 * [AWS S3](source/aws_s3) - read from Amazon Web Services S3 68 * [Google Cloud Storage](source/google_cloud_storage) - read from Google Cloud Platform Storage 69 70 71 72 ## CLI usage 73 74 * Simple wrapper around this library. 75 * Handles ctrl+c (SIGINT) gracefully. 76 * No config search paths, no config files, no magic ENV var injections. 77 78 __[CLI Documentation](cli)__ 79 80 ### Basic usage: 81 82 ``` 83 $ migrate -source file://path/to/migrations -database postgres://localhost:5432/database up 2 84 ``` 85 86 ### Docker usage 87 88 ``` 89 $ docker run -v {{ migration dir }}:/migrations --network host migrate/migrate 90 -path=/migrations/ -database postgres://localhost:5432/database up 2 91 ``` 92 93 ## Use in your Go project 94 95 * API is stable and frozen for this release (v3 & v4). 96 * Uses [Go modules](https://golang.org/cmd/go/#hdr-Modules__module_versions__and_more) to manage dependencies. 97 * To help prevent database corruptions, it supports graceful stops via `GracefulStop chan bool`. 98 * Bring your own logger. 99 * Uses `io.Reader` streams internally for low memory overhead. 100 * Thread-safe and no goroutine leaks. 101 102 __[Go Documentation](https://godoc.org/github.com/golang-migrate/migrate)__ 103 104 ```go 105 import ( 106 "github.com/golang-migrate/migrate/v4" 107 _ "github.com/golang-migrate/migrate/v4/database/postgres" 108 _ "github.com/golang-migrate/migrate/v4/source/github" 109 ) 110 111 func main() { 112 m, err := migrate.New( 113 "github://mattes:personal-access-token@mattes/migrate_test", 114 "postgres://localhost:5432/database?sslmode=enable") 115 m.Steps(2) 116 } 117 ``` 118 119 Want to use an existing database client? 120 121 ```go 122 import ( 123 "database/sql" 124 _ "github.com/lib/pq" 125 "github.com/golang-migrate/migrate/v4" 126 "github.com/golang-migrate/migrate/v4/database/postgres" 127 _ "github.com/golang-migrate/migrate/v4/source/file" 128 ) 129 130 func main() { 131 db, err := sql.Open("postgres", "postgres://localhost:5432/database?sslmode=enable") 132 driver, err := postgres.WithInstance(db, &postgres.Config{}) 133 m, err := migrate.NewWithDatabaseInstance( 134 "file:///migrations", 135 "postgres", driver) 136 m.Steps(2) 137 } 138 ``` 139 140 ## Migration files 141 142 Each migration has an up and down migration. [Why?](FAQ.md#why-two-separate-files-up-and-down-for-a-migration) 143 144 ``` 145 1481574547_create_users_table.up.sql 146 1481574547_create_users_table.down.sql 147 ``` 148 149 [Best practices: How to write migrations.](MIGRATIONS.md) 150 151 ## Supported Major Versions 152 153 Version | Go Modules | Min Go Version | Import | Notes 154 --------|------------|----------------|--------|------ 155 **master** | :white_check_mark: | 1.10.3 | `import "github.com/golang-migrate/migrate/v4"` | New features and bug fixes arrive here first | 156 **v4** | :white_check_mark: | 1.10.3 | `import "github.com/golang-migrate/migrate/v4"` | | 157 **v3** | :x: | 1.10 | `import "github.com/golang-migrate/migrate"` (with package manager) or `import "gopkg.in/golang-migrate/migrate.v3"` (not recommended) | Only security fixes are backported. Only use if your project is not using Go modules. | 158 159 ## Development and Contributing 160 161 Yes, please! [`Makefile`](Makefile) is your friend, 162 read the [development guide](CONTRIBUTING.md). 163 164 Also have a look at the [FAQ](FAQ.md). 165 166 167 168 --- 169 170 Looking for alternatives? [https://awesome-go.com/#database](https://awesome-go.com/#database).