About this project
migrate is a database migration tool written in Go, usable either as a command-line interface or imported as a library into Go projects. It was forked from mattes/migrate.
How it works: migrate reads migration files from a configured source and applies them in the correct order to a target database. The design keeps database drivers lightweight and "dumb" — migrate itself coordinates the logic and validates behavior, and drivers avoid guessing or correcting user input, failing when in doubt.
Supported databases include PostgreSQL, PGX v4 and v5, Redshift, Ql, Cassandra/ScyllaDB, SQLite, SQLite3, SQLCipher, MySQL/MariaDB, Neo4j, MongoDB, CrateDB, Shell, Google Cloud Spanner, CockroachDB, YugabyteDB, ClickHouse, Firebird, MS SQL Server and rqlite. Connection strings use a URL format such as dbdriver://username:password@host:port/dbname?param1=true, and reserved URL characters must be percent-encoded.
Migration sources include the local filesystem, Go io/fs, Go-Bindata, pkger, GitHub, GitHub Enterprise, Bitbucket, GitLab, AWS S3 and Google Cloud Storage.
The CLI is a thin wrapper around the library, handles Ctrl+C (SIGINT) gracefully, and deliberately avoids config search paths, config files or magic environment variable injection. A basic invocation looks like: migrate -source file://path/to/migrations -database postgres://localhost:5432/database up 2. A Docker image (migrate/migrate) is also published.
As a Go library, the API is described as stable and frozen for the v3 and v4 releases, uses Go modules, supports graceful stops via a GracefulStop channel to help avoid database corruption, allows bringing your own logger, uses io.Reader streams internally for low memory overhead, and is described as thread-safe with no goroutine leaks. It can be used standalone or with an existing database client via WithInstance.
Migration files come in pairs of up and down migrations, for example 1481574547_create_users_table.up.sql and .down.sql. The project points to a getting started guide, tutorials for CockroachDB and PostgreSQL, best-practice documentation for writing migrations, and an FAQ. Version v3 is no longer supported; v4 and master are the supported lines.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.