Clone this repo:
  1. d23f71b Merge pull request #305 from zikes/master by Matthias Kadenbach · 3 months ago master
  2. c156f5f replace TRUNCATE with DELETE FROM to avoid schema changes within transaction by Jason Hutchinson · 4 months ago
  3. 69472d5 Merge pull request #301 from shaneodonnell/master by Matthias Kadenbach · 4 months ago
  4. 4ac3ee9 Removed '(always included)' by Shane O'Donnell · 4 months ago
  5. 5b98c13 Merge pull request #281 from ashoda/support_multiple_statements by Matthias Kadenbach · 5 months ago

Build Status GoDoc Coverage Status


Database migrations written in Go. Use as CLI or import as library.

  • Migrate reads migrations from sources and applies them in correct order to a database.
  • Drivers are “dumb”, migrate glues everything together and makes sure the logic is bulletproof.
    (Keeps the drivers lightweight, too.)
  • Database drivers don't assume things or try to correct user input. When in doubt, fail.

Looking for v1?


Database drivers run migrations. Add a new database?

Migration Sources

Source drivers read migrations from local or remote sources. Add a new source?

CLI usage

  • Simple wrapper around this library.
  • Handles ctrl+c (SIGINT) gracefully.
  • No config search paths, no config files, no magic ENV var injections.

CLI Documentation

(brew todo #156)

$ brew install migrate --with-postgres
$ migrate -database postgres://localhost:5432/database up 2

Use in your Go project

  • API is stable and frozen for this release (v3.x).
  • Package migrate has no external dependencies.
  • Only import the drivers you need. (check dependency_tree.txt for each driver)
  • To help prevent database corruptions, it supports graceful stops via GracefulStop chan bool.
  • Bring your own logger.
  • Uses io.Reader streams internally for low memory overhead.
  • Thread-safe and no goroutine leaks.

Go Documentation

import (
    _ ""
    _ ""

func main() {
    m, err := migrate.New(

Want to use an existing database client?

import (
    _ ""
    _ ""

func main() {
    db, err := sql.Open("postgres", "postgres://localhost:5432/database?sslmode=enable")
    driver, err := postgres.WithInstance(db, &postgres.Config{})
    m, err := migrate.NewWithDatabaseInstance(
        "postgres", driver)

Migration files

Each migration has an up and down migration. Why?


Best practices: How to write migrations.

Development and Contributing

Yes, please! Makefile is your friend, read the development guide.

Also have a look at the FAQ.

Looking for alternatives?