golang-migrate /migrate

Database migrations. CLI and Golang library.

★ 19,028⑂ 1,661👁 83⑃ 721● 696▤ 57
GoNOASSERTIONCreated 2018-01-19
下载:v4.20.1v4.20.1 ↓4.20.12026-09-09
-1
日增长
19,028
stars
1,661
forks
83
watchers
721
prs
696
issues
57
releases

README

!Supported Go Versions



 migrate

__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.

Forked from mattes/migrate

 Databases

Database drivers run migrations. Add a new database?

 PostgreSQL
 PGX v4
 PGX v5
 Redshift
 Ql
 Cassandra / ScyllaDB
 SQLite
 SQLite3 (todo 165)
 SQLCipher
 MySQL / MariaDB
 Neo4j
 MongoDB
 CrateDB (todo 170)
 Shell (todo 171)
 Google Cloud Spanner
 CockroachDB
 YugabyteDB
 ClickHouse
 Firebird
 MS SQL Server
 rqlite

 Database URLs

Database connection strings are specified via URLs. The URL format is driver dependent but generally has the form: dbdriver://username:password@host:port/dbname?param1=true&param2=false

Any reserved URL characters need to be escaped. Note, the % character also needs to be escaped

Explicitly, the following characters need to be escaped:
!, , $, %, &, ', (, ), , +, ,, /, :, ;, =, ?, @, [, ]

It's easiest to always run the URL parts of your DB connection URL (e.g. username, password, etc) through an URL encoder. See the example Python snippets below:

bash
$ python3 -c 'import urllib.parse; print(urllib.parse.quote(input("String to encode: "), ""))'
String to encode: FAKEpassword!$%&'()+,/:;=?@[]
FAKEpassword%21%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D
$ python2 -c 'import urllib; print urllib.quote(raw_input("String to encode: "), "")'
String to encode: FAKEpassword!$%&'()+,/:;=?@[]
FAKEpassword%21%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D
$


 Migration Sources

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

 Filesystem - read from filesystem
 io/fs - read from a Go io/fs
 Go-Bindata - read from embedded binary data (jteeuwen/go-bindata)
 pkger - read from embedded binary data (markbates/pkger)
 GitHub - read from remote GitHub repositories
 GitHub Enterprise - read from remote GitHub Enterprise repositories
 Bitbucket - read from remote Bitbucket repositories
 Gitlab - read from remote Gitlab repositories
 AWS S3 - read from Amazon Web Services S3
 Google Cloud Storage - read from Google Cloud Platform Storage

 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 (includes CLI install instructions)

 Basic usage

bash
$ migrate -source file://path/to/migrations -database postgres://localhost:5432/database up 2


 Docker usage

bash
$ docker run -v {{ migration dir }}:/migrations --network host migrate/migrate
    -path=/migrations/ -database postgres://localhost:5432/database up 2


 Use in your Go project

 API is stable and frozen for this release (v3 & v4).
 Uses Go modules t

Top issues

Discussions

Latest release

v4.20.1 v4.20.1 2026-09-09
[!NOTE]
 This release is the immediate mitigation of the CI / release failure in v4.20.0, to distribute the latest version to all registries.

 What's Changed
 ci: fix GoReleaser build matrix by @Fontinalis in https://github.com/golang-migrate/migrate/pull/1434


Full Changelog: https://github.com/golang-migrate/migrate/compare/v4.20.0...v4.20.1

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON