explaingit

golang-migrate/migrate

18,501GoAudience · developerComplexity · 2/5MaintainedLicenseSetup · easy

TLDR

A database migration tool for Go that reads versioned SQL files, applies them to your database in order, and tracks what's been run, preventing your database schema from drifting out of sync with your code.

Mindmap

mindmap
  root((migrate))
    What it does
      Applies versioned changes
      Tracks migration history
      Supports rollbacks
      Manages schema drift
    Supported databases
      PostgreSQL MySQL
      SQLite MongoDB
      CockroachDB SQL Server
    Migration sources
      Local filesystem
      Embedded binaries
      GitHub Bitbucket
      S3 Cloud Storage
    How to use it
      CLI tool
      Go library
      Docker image
    Key features
      Thread-safe
      Low memory usage
      Graceful cancellation
      Stable API

Things people build with this

USE CASE 1

Deploy database schema changes alongside application updates without manual SQL scripts.

USE CASE 2

Roll back a failed migration to restore the previous database state when something goes wrong.

USE CASE 3

Store migration files in your Git repository and apply them automatically in CI/CD pipelines.

USE CASE 4

Embed migrations directly in a compiled Go binary so the database schema updates when the app starts.

Tech stack

GoPostgreSQLMySQLSQLiteMongoDBDocker

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose, including commercial use, as long as you keep the copyright notice and license text.

In plain English

migrate is a database migration tool for Go, available both as a command-line program and as an importable library. Database migrations are the controlled, versioned changes made to a database's structure over time, for example, adding a new column to a table or creating a new table entirely. Managing these changes systematically prevents databases from drifting out of sync with the application code that uses them. The tool reads migration files from a source, applies them to a database in the correct order, and tracks which migrations have already run. Migration files come in pairs: one file applies a change (the "up" direction) and one reverses it (the "down" direction), allowing rollbacks. Sources for migration files include the local filesystem, embedded binary data in a Go binary, remote GitHub repositories, Bitbucket, GitLab, AWS S3, and Google Cloud Storage. A wide range of databases are supported as migration targets, including PostgreSQL, MySQL, MariaDB, SQLite, MongoDB, CockroachDB, ClickHouse, Microsoft SQL Server, Cassandra, and others. Database connection strings are passed as URLs. The library is thread-safe, uses streaming internally to minimize memory usage, and supports graceful cancellation via a stop channel. The API has been stable since version 4. A Docker image is also available for running migrations without installing Go.

Copy-paste prompts

Prompt 1
Show me how to set up migrate to run PostgreSQL migrations from my local filesystem using the CLI.
Prompt 2
How do I embed database migrations into my Go binary so they run automatically on startup?
Prompt 3
Write a Go program that uses the migrate library to apply MySQL migrations from an S3 bucket.
Prompt 4
How do I roll back the last migration if something went wrong in production?
Prompt 5
Can I use migrate to manage migrations for multiple databases in the same application?
Open on GitHub → Explain another repo

Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.