Giter Site home page Giter Site logo

migrate's Introduction

You are looking at a deprecated version.

Use the latest version instead.

How to build a static binary for Linux from MacOS:

brew install FiloSottile/musl-cross/musl-cross
CC=x86_64-linux-musl-gcc CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o migrate.linux_amd64 -ldflags "-linkmode external -extldflags -static -s -w" -a

migrate

Build Status

A migration helper written in Go. Use it in your existing Golang code or run commands via the CLI.

GoCode   import github.com/housinganywhere/migrate/migrate
CLI      go get -u github.com/housinganywhere/migrate

Features

  • Super easy to implement Driver interface.
  • Gracefully quit running migrations on ^C.
  • No magic search paths routines, no hard-coded config files.
  • CLI is build on top of the migrate package.

Available Drivers

Need another driver? Just implement the Driver interface and open a PR.

Usage from Terminal

# install
go get github.com/housinganywhere/migrate

# create new migration file in path
migrate -url driver://url -path ./migrations create migration_file_xyz

# apply all available migrations
migrate -url driver://url -path ./migrations up

# roll back all migrations
migrate -url driver://url -path ./migrations down

# roll back the most recently applied migration, then run it again.
migrate -url driver://url -path ./migrations redo

# run down and then up command
migrate -url driver://url -path ./migrations reset

# show the current migration version
migrate -url driver://url -path ./migrations version

# apply the next n migrations
migrate -url driver://url -path ./migrations migrate +1
migrate -url driver://url -path ./migrations migrate +2
migrate -url driver://url -path ./migrations migrate +n

# roll back the previous n migrations
migrate -url driver://url -path ./migrations migrate -1
migrate -url driver://url -path ./migrations migrate -2
migrate -url driver://url -path ./migrations migrate -n

# go to specific migration
migrate -url driver://url -path ./migrations goto 1
migrate -url driver://url -path ./migrations goto 10
migrate -url driver://url -path ./migrations goto v

Usage in Go

See GoDoc here: http://godoc.org/github.com/housinganywhere/migrate/migrate

import "github.com/housinganywhere/migrate/migrate"

// Import any required drivers so that they are registered and available
import _ "github.com/housinganywhere/migrate/driver/mysql"

// use synchronous versions of migration functions ...
allErrors, ok := migrate.UpSync("driver://url", "./path")
if !ok {
  fmt.Println("Oh no ...")
  // do sth with allErrors slice
}

// use the asynchronous version of migration functions ...
pipe := migrate.NewPipe()
go migrate.Up(pipe, "driver://url", "./path")
// pipe is basically just a channel
// write your own channel listener. see writePipe() in main.go as an example.

Migration files

The format of migration files looks like this:

1481574547_initial_plan_to_do_sth.up.sql     # up migration instructions
1481574547_initial_plan_to_do_sth.down.sql   # down migration instructions
1482438365_xxx.up.sql
1482438365_xxx.down.sql
...

Why two files? This way you could still do sth like psql -f ./db/migrations/1481574547_initial_plan_to_do_sth.up.sql and there is no need for any custom markup language to divide up and down migrations. Please note that the filename extension depends on the driver.

Alternatives

migrate's People

Contributors

mattes avatar dimag-jfrog avatar dinedal avatar dacamp avatar raizyr avatar johnweldon avatar balboah avatar skeswa avatar dereulenspiegel avatar ngauthier avatar divoxx avatar buddhamagnet avatar hivectl avatar justinas avatar daddykotex avatar meehow avatar goenning avatar benma avatar trietphm avatar wlcx avatar raphaeljlps avatar uzimonkey avatar sekimura avatar jmhodges avatar jamiecuthill avatar slockij avatar fregalle avatar lefelys avatar drboyer avatar lepoetemaudit avatar

Watchers

Ramkumar  avatar João Henrique Machado Silva avatar Maksim Terekhin avatar James Cloos avatar Henrique Vicente avatar Prakash Wadhwani avatar Lucas de Souza Santos avatar Shantanu Raj avatar Simone Potenza avatar Felix Enescu avatar  avatar Dyaa avatar  avatar Yuri Buerov avatar Vlad Dyachenko avatar Oxana avatar Shabbir Hossain avatar  avatar Gustavo Bini avatar  avatar Dmitrii Lobanov avatar Neil Shah avatar  avatar Djordy Seelmann avatar Arjun Bhandage avatar Blessing Pariola avatar Mahdi Valizadeh avatar Alessandra avatar Joshua Folivi avatar Alex Tutea avatar Eldar avatar   avatar Tharun Rajendran avatar  avatar Michalis Papilaris avatar Nana Adjei Manu avatar Anna avatar Roshan Bista avatar  avatar Casprine Assempah avatar Adebisi Oluwabukunmi avatar Oğuzhan Gür avatar

Forkers

slockij

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.