migrate
A generic file migration tool that applies ordered transformations to a project directory. Think database migrations, but for files and project setup. Migrations can be written in any language (bash, TypeScript, Python, etc.) using shebangs.
Install
Option 1: Download binary (easiest)
Download the pre-built binary for your platform from GitHub Releases, then move it to a directory in your PATH:
# Example for macOS (Apple Silicon)
Option 2: cargo-binstall (recommended if you have Rust)
If you have Rust installed, cargo-binstall downloads pre-built binaries:
# Install cargo-binstall first (if you don't have it)
# Then install migrate
Option 3: cargo install
Requires Rust:
Option 4: Build from source
Usage
Check migration status
Apply pending migrations
Preview changes without applying
Create a new migration
# Create a bash migration (default)
# Create a TypeScript migration
# Create with description
# List available templates
Writing Migrations
Migration files use the format XXXXX-name.{sh,ts,py,...} where XXXXX is a 5-character base36 version automatically generated by migrate create. The version encodes the creation timestamp, ensuring migrations sort chronologically.
Migrations are executable files that receive context via environment variables:
MIGRATE_PROJECT_ROOT=/path/to/project # Absolute path to project root
MIGRATE_MIGRATIONS_DIR=/path/to/migrations # Where migration files live
MIGRATE_ID=1fb2g-initial-setup # Current migration ID (includes version)
MIGRATE_DRY_RUN=true|
Bash example
#!/usr/bin/env bash
# Description: Add TypeScript configuration
TypeScript example
#!/usr/bin/env -S npx tsx
// Description: Add configuration file
import * as fs from 'fs/promises';
import * as path from 'path';
const projectRoot = process.env.MIGRATE_PROJECT_ROOT!;
const config = {
version: 1,
features: ['auth', 'api']
};
await fs.writeFile(
path.join(projectRoot, 'config.json'),
JSON.stringify(config, null, 2)
);
Migrations run in order by their version prefix (e.g., 1fb2g-) and are tracked in a .history file.
CLI Reference
| Command | Description |
|---|---|
migrate status |
Show applied and pending migrations |
migrate up |
Apply all pending migrations |
migrate create <name> |
Create a new migration file |
Options
| Option | Description | Default |
|---|---|---|
-r, --root <path> |
Project root directory | . |
-m, --migrations <path> |
Migrations directory | migrations |
--dry-run |
Preview changes (up only) | false |
-t, --template <name> |
Template to use (create only) | bash |
-d, --description <text> |
Migration description (create only) | - |
--list-templates |
List available templates (create only) | - |
Available Templates
bash- Shell script (.sh)ts- TypeScript via tsx (.ts)python- Python 3 (.py)node- Node.js (.js)ruby- Ruby (.rb)
Development
# Clone and setup
# Common commands
# Build release