gofasta migrate
Runs database migrations using the golang-migrate tool with SQL files in the db/migrations/ directory. Supports applying all pending migrations or rolling back.
Usage
gofasta migrate <direction>Where <direction> is either up or down.
This command takes no flags.
Subcommands
| Subcommand | Description |
|---|---|
up | Run all pending migrations |
down | Roll back migrations |
Examples
Run all pending migrations:
gofasta migrate upRoll back migrations:
gofasta migrate downHow It Works
The gofasta migrate command delegates to the golang-migrate tool:
migrate -path db/migrations -database <url> <direction>The database URL is built from your config/config.yaml settings, with GOFASTA_ prefixed environment variable overrides applied.
Supported Databases
| Driver | Description |
|---|---|
postgres | PostgreSQL |
mysql | MySQL / MariaDB |
sqlite | SQLite |
sqlserver | Microsoft SQL Server |
clickhouse | ClickHouse |
Database Configuration
The migration command reads database connection settings from config/config.yaml:
database:
driver: postgres
host: localhost
port: 5432
name: myapp_dev
user: postgres
password: postgresSettings can be overridden using GOFASTA_ prefixed environment variables.
Migration File Format
Up migrations contain SQL statements to apply changes:
-- db/migrations/000006_create_products.up.sql
CREATE TABLE products (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(255) NOT NULL,
price DECIMAL(10,2) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
deleted_at TIMESTAMP
);
CREATE INDEX idx_products_deleted_at ON products(deleted_at);Down migrations contain SQL statements to reverse changes:
-- db/migrations/000006_create_products.down.sql
DROP TABLE IF EXISTS products;Related
- gofasta seed — run database seeders
- gofasta init — initialize a project including running migrations
- gofasta dev — dev server runs migrations automatically if DB is available
Last updated on