migrate

command module
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2017 License: MIT Imports: 19 Imported by: 0

README

You are looking at a deprecated version.

Use the latest version instead.


migrate

Build Status

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

GoCode   import gopkg.in/mattes/migrate.v1/migrate
CLI      go get -u gopkg.in/mattes/migrate.v1

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 gopkg.in/mattes/migrate.v1

# 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/gopkg.in/mattes/migrate.v1/migrate

import "gopkg.in/mattes/migrate.v1/migrate"

// Import any required drivers so that they are registered and available
import _ "gopkg.in/mattes/migrate.v1/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

Documentation

Overview

Package main is the CLI. You can use the CLI via Terminal. import "gopkg.in/mattes/migrate.v1/migrate" for usage within Go.

Directories

Path Synopsis
Package driver holds the driver interface.
Package driver holds the driver interface.
bash
Package bash implements the Driver interface.
Package bash implements the Driver interface.
cassandra
Package cassandra implements the Driver interface.
Package cassandra implements the Driver interface.
crate
Package crate implements a driver for the Crate.io database
Package crate implements a driver for the Crate.io database
mssql
Package mssql implements the Driver interface.
Package mssql implements the Driver interface.
mysql
Package mysql implements the Driver interface.
Package mysql implements the Driver interface.
neo4j
Package neo4j implements the Driver interface.
Package neo4j implements the Driver interface.
postgres
Package postgres implements the Driver interface.
Package postgres implements the Driver interface.
ql
sqlite3
Package sqlite3 implements the Driver interface.
Package sqlite3 implements the Driver interface.
Package file contains functions for low-level migration files handling.
Package file contains functions for low-level migration files handling.
Package migrate is imported by other Go code.
Package migrate is imported by other Go code.
direction
Package direction just holds convenience constants for Up and Down migrations.
Package direction just holds convenience constants for Up and Down migrations.
Package pipe has functions for pipe channel handling.
Package pipe has functions for pipe channel handling.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL