{"id":22993890,"url":"https://github.com/erizocosmico/mig","last_synced_at":"2026-04-11T14:35:49.426Z","repository":{"id":57603778,"uuid":"97258287","full_name":"erizocosmico/mig","owner":"erizocosmico","description":"Dead simple Go migration tool and library that keeps your migrations inside a binary.","archived":false,"fork":false,"pushed_at":"2017-07-26T20:17:52.000Z","size":44,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-08T03:33:48.193Z","etag":null,"topics":["database","golang","migrations","mssql","mysql","postgresql","sqlite3"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erizocosmico.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-14T17:35:10.000Z","updated_at":"2018-04-04T05:52:18.000Z","dependencies_parsed_at":"2022-08-27T22:03:25.121Z","dependency_job_id":null,"html_url":"https://github.com/erizocosmico/mig","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erizocosmico%2Fmig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erizocosmico%2Fmig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erizocosmico%2Fmig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erizocosmico%2Fmig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erizocosmico","download_url":"https://codeload.github.com/erizocosmico/mig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246814830,"owners_count":20838336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","golang","migrations","mssql","mysql","postgresql","sqlite3"],"created_at":"2024-12-15T05:15:30.034Z","updated_at":"2025-12-30T23:10:50.837Z","avatar_url":"https://github.com/erizocosmico.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ![mig](https://cdn.rawgit.com/erizocosmico/mig/d0481b14/mig.svg)\n\n[![Build Status](https://travis-ci.org/erizocosmico/mig.svg?branch=master)](https://travis-ci.org/erizocosmico/mig) [![GoDoc](https://godoc.org/github.com/erizocosmico/mig?status.svg)](https://godoc.org/github.com/erizocosmico/mig) [![codecov](https://codecov.io/gh/erizocosmico/mig/branch/master/graph/badge.svg)](https://codecov.io/gh/erizocosmico/mig) [![Go Report Card](https://goreportcard.com/badge/github.com/erizocosmico/mig)](https://goreportcard.com/report/github.com/erizocosmico/mig)\n\nDead simple Go migration tool and library that keeps your migrations inside a binary (or your application's own binary) for ease of use.\n\n## Install\n\n```\ngo get -v github.com/erizocosmico/mig/...\n```\n\n## Get started\n\nFirst thing we should do is the following:\n\n* Go to the root of your project\n* Run `mkdir migrations`\n* Run `mig scaffold --db postgres` (you can change postgres for any of the supported database drivers)\n\nBy now we'll have something like this:\n\n```\n| myproject/\n    |- migrations/\n    |- cmd/\n        |- migrate/\n            |- main.go\n```\n\nThat `migrate` command is the binary we'll use to manage our migrations. Note that we didn't have to configure anything in the scaffold command other than the database because we used the default `./migrations` as the package for our migrations.\n\nNow we can start writing our migrations.\n\n```\nmig new initial_schema\nmig new add_sessions_table\nmig new add_profile_picture_column\n```\n\nThat command will add new migration files inside the `migrations` directory.\n\nYou can edit them and place your migrations. It's Go code, so you can do whatever thing you want in there.\n\nThe migration files generated will look like this:\n\n```go\npackage migrations\n\nimport \"github.com/erizocosmico/mig\"\n\nfunc main() {\n        mig.Register(\n                func(db mig.DB) error {\n                        // your up code\n                },\n                func(db mig.DB) error {\n                        // your down code\n                },\n        )\n}\n```\n\nYou will be thinking \"do I have to make all the execs and if err != nil by hand?\". No! `mig`'s got you covered! There are some utility functions [`mig.ExecAll`](https://godoc.org/github.com/erizocosmico/mig#ExecAll) and [`mig.DropAll`](https://godoc.org/github.com/erizocosmico/mig#DropAll) that should cover almost all your use cases. Check them out in the documentation.\n\nNow, to execute you can run the generated command or build it and use it as a binary.\n\n```\ngo ./cmd/migrate/main.go --help\n```\n\nor (assuming your `~/$GOPATH/bin` is in your PATH)\n\n```\ngo install ./cmd/migrate/...\nmigrate --help\n```\n\nThere are 3 commands available in the migration manager:\n\n* `up` runs all the migrations.\n* `rollback` executes the down for the current version, leaving the database in the previous state e.g. if database is in version 3, this would get it to version 2.\n* `to-version` get the database to a specific version.\n\n```\nmigrate up --url postgres://postgres:@0.0.0.0:5432/testing?sslmode=disable\n```\n\nYou can pass the URL as an environment variable as well:\n\n```\nDBURL=postgres://postgres:@0.0.0.0:5432/testing?sslmode=disable migrate to-version 5\n```\n\n## Using the API programmatically\n\nLucky for you, the API can be used programmatically as well. Do you want to import your migrations? Easy, import them, it's just Go code.\n\n```\npackage main\n\nimport (\n        _ \"my/package/migrations\"\n)\n\n// do something\n```\n\nCheck the [documentation](https://godoc.org/github.com/erizocosmico/mig) to see the list of available functionality, which is the same that is available using the generated command.\n\nWhy could this be useful? In case you want your binary to autoupdate itself accordingly. The downside of this is that all migrations code would be inside your main binary. That's why the `mig` tool scaffolds a separate command just for migration management.\n\n## Supported drivers\n\n* [MySQL](https://github.com/go-sql-driver/mysql)\n* [PostgreSQL](https://github.com/lib/pq)\n* [MSSQL](https://github.com/denisenkom/go-mssqldb)\n* [SQLite3](https://github.com/mattn/go-sqlite3)\n\n## Acknowledgements\n\n[go-pg/migrations](https://github.com/go-pg/migrations) for the inspiration. This library is basically `migrations` but it creates the migrations without needing to query the database or create the manager command yourself for the migrations. It also supports more databases than just PostgreSQL.\n\n## LICENSE\n\nMIT, see [LICENSE](/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferizocosmico%2Fmig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferizocosmico%2Fmig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferizocosmico%2Fmig/lists"}