Skip to content
forked from mattes/migrate

Database migration handling in Golang

License

Notifications You must be signed in to change notification settings

konjoot/migrate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

migrate

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

This is lite version of mattes/migrate library for PostgreSQL only. Therefore, the following dependencies are removed:

  • driver for Cassandra
  • driver for MySQL
  • driver for SQLite
GoCode   import github.com/konjoot/migrate/migrate

Features

  • Super easy to implement Driver interface.
  • Gracefully quit running migrations on ^C.
  • No magic search paths routines, no hard-coded config files.

Available Drivers

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

Usage in Go

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

import "github.com/konjoot/migrate/migrate"

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

// 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:

001_initial_plan_to_do_sth.up.sql     # up migration instructions
001_initial_plan_to_do_sth.down.sql   # down migration instructions
002_xxx.up.sql
002_xxx.down.sql
...

Why two files? This way you could still do sth like psql -f ./db/migrations/001_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

About

Database migration handling in Golang

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%