explaingit

amacneil/dbmate

6,892GoAudience · developerComplexity · 2/5Setup · easy

TLDR

A language-agnostic command-line tool for managing database schema migrations using plain SQL files, compatible with MySQL, PostgreSQL, SQLite, ClickHouse, BigQuery, and Spanner.

Mindmap

mindmap
  root((dbmate))
    What it does
      Database migrations
      Plain SQL files
      Schema snapshots
    Supported Databases
      PostgreSQL
      MySQL
      SQLite
      ClickHouse
    Key Features
      Timestamp file names
      Transaction safety
      schema.sql output
      Docker ready
    Install Methods
      Homebrew
      npm
      Docker image
      Single binary
    Audience
      Any-language teams
      Backend developers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Keep database schemas in sync across a team of developers regardless of what programming language each person uses.

USE CASE 2

Automate schema migrations in a Docker-based deployment pipeline using the dbmate Docker image.

USE CASE 3

Generate a plain-text schema.sql snapshot after every migration so database changes are reviewable in version control.

Tech stack

GoSQL

Getting it running

Difficulty · easy Time to first run · 5min

Requires a running database instance, connection is configured via DATABASE_URL environment variable or a .env file.

In plain English

Dbmate is a command-line tool for managing database migrations. A migration is a versioned change to a database schema, such as adding a new table, renaming a column, or creating an index. When multiple developers are working on the same project, or when you need to deploy changes to a production server, keeping everyone's database structure in sync can get messy. Dbmate solves this by letting you write migration files in plain SQL, track which ones have been run, and apply or roll back changes in a consistent order across all environments. The tool works with MySQL, PostgreSQL, SQLite, ClickHouse, BigQuery, and Spanner. Because it uses plain SQL rather than a language-specific API, it does not depend on any particular programming framework or language. The same tool can be used on a team that mixes Go, Node.js, Python, Ruby, or any other language, which is one of the stated reasons it was built. Migration files are named with a timestamp prefix, which prevents version number conflicts when two developers create migrations independently and then merge their work. Each migration is run inside a database transaction, so a partially applied migration will be rolled back automatically if something goes wrong. Dbmate also saves a schema.sql file after each migration, giving you a plain-text snapshot of the full database structure that can be reviewed in version control like any other file. The database connection is configured through an environment variable called DATABASE_URL, and dbmate automatically reads a .env file in the current directory so you do not have to set variables manually in development. Commands cover the full migration lifecycle: creating a new migration file, running pending migrations, rolling back the most recent one, checking migration status, creating or dropping the database, and waiting for the database to become available before running a command (useful in Docker-based setups). Dbmate ships as a single binary with no dependencies. It can be installed via Homebrew on macOS, npm, a direct binary download on Linux, Scoop on Windows, or pulled as a Docker image. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Using dbmate, set up a migration workflow for a PostgreSQL database in a Node.js project, show me the folder structure, a sample migration file, and the commands to apply and roll back.
Prompt 2
Write a dbmate migration SQL file that adds a created_at timestamp column to an existing users table and includes the rollback.
Prompt 3
Show me how to configure dbmate to connect to a SQLite database via DATABASE_URL and run all pending migrations automatically in a CI pipeline.
Prompt 4
Using dbmate with Docker Compose, how do I make my app container wait for the database to be ready before running migrations on startup?
Open on GitHub → Explain another repo

← amacneil on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.