golang-migrate /migrate
Database migrations. CLI and Golang library.
★ 19,028⑂ 1,661👁 83⑃ 721● 696▤ 57
-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¶m2=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 tTop issues
#35file does not exist error53 comments · 2018-05-18#179History of applied migrations29 comments · 2019-02-26#174Too many dependencies29 comments · 2019-02-17#510Tracking which migrations have been applied in the schema_migrations table24 comments · 2021-02-24#395golang-migrate with different projects same database20 comments · 2020-05-22#470[PROPOSAL] Use manifest file to track migration sources16 comments · 2020-11-08#15Support for golang migrations16 comments · 2018-03-14#380Can't execute migrations for Clickhouse15 comments · 2020-04-23
Discussions
#1437v4.20.10 comments · 2026-09-09#1436v4.20.00 comments · 2026-09-09#1421Vertica database support1 comments · 2026-08-08#1403repository status0 comments · 2026-06-19#1369hana support1 comments · 2026-03-11#1339v4.19.10 comments · 2025-11-29#1316Proposal to Implement GitHub Apps Authentication for Private Repository Sources0 comments · 2025-09-10#1312v4.19.00 comments · 2025-08-29
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