2gis/migrate

Name: migrate

Owner: 2GIS

Description: Database migrations. CLI and Golang library.

Created: 2018-03-15 02:10:12.0

Updated: 2018-03-15 05:37:40.0

Pushed: 2018-03-15 05:37:38.0

Homepage:

Size: 488

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status GoDoc Coverage Status packagecloud.io

migrate

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

Looking for v1?

Databases

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

CLI Documentation

(brew todo #156)

ew install migrate --with-postgres
grate -database postgres://localhost:5432/database up 2
Use in your Go project

Go Documentation

rt (
"github.com/mattes/migrate"
_ "github.com/mattes/migrate/database/postgres"
_ "github.com/mattes/migrate/source/github"


 main() {
m, err := migrate.New(
    "github://mattes:personal-access-token@mattes/migrate_test",
    "postgres://localhost:5432/database?sslmode=enable")
m.Steps(2)

Want to use an existing database client?

rt (
"database/sql"
_ "github.com/lib/pq"
"github.com/mattes/migrate"
"github.com/mattes/migrate/database/postgres"
_ "github.com/mattes/migrate/source/file"


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

Migration files

Each migration has an up and down migration. Why?

574547_create_users_table.up.sql
574547_create_users_table.down.sql

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? https://awesome-go.com/#database.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.