How golang-migrate/migrate works
golang-migrate is a Go library and CLI for applying ordered, versioned database migrations. Its principal workflow is to open a migration source and database driver, read up/down migration streams, and apply them while tracking migration state; the CLI is a thin entry point to the same engine. The README documents filesystem, embedded, Git-hosted, and cloud sources plus many database backends. Source excerpts are limited, so subsystem-level links rely on the README rather than inferred calls between individual drivers.
Main entry points: source/driver.go Source driver API · migrate.go Migration engine · database/driver.go Database driver API · main.go CLI
Components 15
Entrypoints
- CLI
internal/cli/main.go
Migration engine
- Migration engine
migrate.go - Migration model
migration.go
Migration sources
- Source driver API
source/driver.go - Migration parsing
source/parse.go - Filesystem sources
source/file/file.go - Embedded sources
source/iofs/iofs.go - Git hosting sources
source/github/github.go - Cloud storage sources
source/aws_s3/s3.go
Database drivers
- Database driver API
database/driver.go - SQL database drivers
database/postgres/postgres.go - NoSQL database drivers
database/mongodb/mongodb.go
Other components
- CLI user
- Go application
- Target database
Connections 13
- CLI user → CLI: runs commands
README.md - CLI → Migration engine: initializes
internal/cli/main.go - Go application → Migration engine: calls API
README.md - Migration engine → Source driver API: reads migrations
README.md - Migration engine → Database driver API: applies migrations
README.md - Filesystem sources → Source driver API: implements
README.md - Embedded sources → Source driver API: implements
README.md - Git hosting sources → Source driver API: implements
README.md - Cloud storage sources → Source driver API: implements
README.md - Migration parsing → Migration model: parses files
- SQL database drivers → Database driver API: implements
README.md - NoSQL database drivers → Database driver API: implements
README.md - Database driver API → Target database: executes against
README.md