Skip to Content

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

SubcommandDescription
upRun all pending migrations
downRoll back migrations

Examples

Run all pending migrations:

gofasta migrate up

Roll back migrations:

gofasta migrate down

How 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

DriverDescription
postgresPostgreSQL
mysqlMySQL / MariaDB
sqliteSQLite
sqlserverMicrosoft SQL Server
clickhouseClickHouse

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: postgres

Settings 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;
  • 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