rango migrate
Applies pending SQL migration files to the database.
Basic usage
DATABASE_URL=postgres://user:pass@localhost/mydb rango migrate
Output:
🔌 Connecting to database (postgres)...
⏭ 0001_user.sql (already applied)
▶ Applying 0002_post.sql...
✅ 0002_post.sql
✅ Applied 1 migration(s).
Options
# Custom migrations directory
rango migrate --migrations db/migrations
# Custom database URL
rango migrate --database-url postgres://...
Migration tracking
Rango creates a _rango_migrations table in your database to track applied migrations:
-- Postgres
CREATE TABLE _rango_migrations (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
applied_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- SQLite
CREATE TABLE _rango_migrations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE,
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
);
Order of execution
Migrations are applied in alphabetical order (which matches their numbered prefix):
0001_user.sql ← applied first
0002_post.sql ← applied second
0003_tag_post.sql ← applied third
Idempotency
Already-applied migrations are skipped. Running rango migrate twice is safe.
DATABASE_URL
The database URL is resolved in this order:
--database-urlCLI flagMIGRATE_DATABASE_URLenvironment variableDATABASE_URLenvironment variable
MIGRATE_DATABASE_URL lets migrations run as a role that owns the schema (DDL) while the
application's DATABASE_URL uses a role limited to reading and writing rows (DML).