github.com/Komiflo/migrate@v3.0.1-0.20170427064301-ee4a6a3c6f42+incompatible/README.md (about) 1 # You are looking at a deprecated version. 2 # Use the [latest version](https://github.com/komiflo/migrate) instead. 3 4 --- 5 6 # migrate 7 8 [![Build Status](https://travis-ci.org/mattes/migrate.svg?branch=v1)](https://travis-ci.org/mattes/migrate) 9 10 A migration helper written in Go. Use it in your existing Golang code 11 or run commands via the CLI. 12 13 ``` 14 GoCode import github.com/komiflo/migrate/migrate 15 CLI go get -u github.com/komiflo/migrate 16 ``` 17 18 __Features__ 19 20 * Super easy to implement [Driver interface](http://godoc.org/github.com/komiflo/migrate/driver#Driver). 21 * Gracefully quit running migrations on ``^C``. 22 * No magic search paths routines, no hard-coded config files. 23 * CLI is build on top of the ``migrate package``. 24 25 26 ## Available Drivers 27 28 * [PostgreSQL](driver/postgres) 29 * [Cassandra](driver/cassandra) 30 * [SQLite](driver/sqlite3) 31 * [MySQL](driver/mysql) ([experimental](https://github.com/komiflo/migrate/issues/1#issuecomment-58728186)) 32 * [Neo4j](driver/neo4j) 33 * [Ql](driver/ql) 34 * [MongoDB](driver/mongodb) 35 * [CrateDB](driver/crate) 36 * [MSSQL](driver/mssql) 37 38 Need another driver? Just implement the [Driver interface](http://godoc.org/github.com/komiflo/migrate/driver#Driver) and open a PR. 39 40 41 ## Usage from Terminal 42 43 ```bash 44 # install 45 go get github.com/komiflo/migrate 46 47 # create new migration file in path 48 migrate -url driver://url -path ./migrations create migration_file_xyz 49 50 # apply all available migrations 51 migrate -url driver://url -path ./migrations up 52 53 # roll back all migrations 54 migrate -url driver://url -path ./migrations down 55 56 # roll back the most recently applied migration, then run it again. 57 migrate -url driver://url -path ./migrations redo 58 59 # run down and then up command 60 migrate -url driver://url -path ./migrations reset 61 62 # show the current migration version 63 migrate -url driver://url -path ./migrations version 64 65 # apply the next n migrations 66 migrate -url driver://url -path ./migrations migrate +1 67 migrate -url driver://url -path ./migrations migrate +2 68 migrate -url driver://url -path ./migrations migrate +n 69 70 # roll back the previous n migrations 71 migrate -url driver://url -path ./migrations migrate -1 72 migrate -url driver://url -path ./migrations migrate -2 73 migrate -url driver://url -path ./migrations migrate -n 74 75 # go to specific migration 76 migrate -url driver://url -path ./migrations goto 1 77 migrate -url driver://url -path ./migrations goto 10 78 migrate -url driver://url -path ./migrations goto v 79 ``` 80 81 82 ## Usage in Go 83 84 See GoDoc here: http://godoc.org/github.com/komiflo/migrate/migrate 85 86 ```go 87 import "github.com/komiflo/migrate/migrate" 88 89 // Import any required drivers so that they are registered and available 90 import _ "github.com/komiflo/migrate/driver/mysql" 91 92 // use synchronous versions of migration functions ... 93 allErrors, ok := migrate.UpSync("driver://url", "./path") 94 if !ok { 95 fmt.Println("Oh no ...") 96 // do sth with allErrors slice 97 } 98 99 // use the asynchronous version of migration functions ... 100 pipe := migrate.NewPipe() 101 go migrate.Up(pipe, "driver://url", "./path") 102 // pipe is basically just a channel 103 // write your own channel listener. see writePipe() in main.go as an example. 104 ``` 105 106 ## Migration files 107 108 The format of migration files looks like this: 109 110 ``` 111 1481574547_initial_plan_to_do_sth.up.sql # up migration instructions 112 1481574547_initial_plan_to_do_sth.down.sql # down migration instructions 113 1482438365_xxx.up.sql 114 1482438365_xxx.down.sql 115 ... 116 ``` 117 118 Why two files? This way you could still do sth like 119 ``psql -f ./db/migrations/1481574547_initial_plan_to_do_sth.up.sql`` and there is no 120 need for any custom markup language to divide up and down migrations. Please note 121 that the filename extension depends on the driver. 122 123 124 ## Alternatives 125 126 * https://bitbucket.org/liamstask/goose 127 * https://github.com/tanel/dbmigrate 128 * https://github.com/BurntSushi/migration 129 * https://github.com/DavidHuie/gomigrate 130 * https://github.com/rubenv/sql-migrate 131 132