migrate
Run all pending migrations against a D1 database. Migrations are tracked in the _migrations table, which is created automatically on first run. Already-applied migrations are skipped, so this command is safe to run multiple times.
Synopsis
bash
npx @orphnet/d1-eloquent migrate --db <DB_NAME> [--local | --remote] [--atomic]Options
| Flag | Description |
|---|---|
--db <DB_NAME> | Required. The D1 binding name defined in wrangler.toml. |
--local | Run against the local D1 database (used with wrangler dev). Default when neither flag is provided. |
--remote | Run against the Cloudflare-hosted D1 database. |
--atomic | Wrap all pending migrations in a single transaction. Available for remote execution only. |
Examples
Run pending migrations against a local database:
bash
npx @orphnet/d1-eloquent migrate --db MY_DB --localRun pending migrations against the remote Cloudflare D1 database:
bash
npx @orphnet/d1-eloquent migrate --db MY_DB --remoteRun all pending migrations atomically on remote (all succeed or all roll back):
bash
npx @orphnet/d1-eloquent migrate --db MY_DB --remote --atomicNotes
- The
_migrationstable is created automatically if it does not exist. - Migration files are discovered in
src/database/migrations/and sorted by filename (timestamp prefix ensures correct order). - Use
make:migrationto generate new migration files. See Generators.
status
Check which migrations have been applied and which are still pending.
Synopsis
bash
npx @orphnet/d1-eloquent status --db <DB_NAME> [--local | --remote]Options
| Flag | Description |
|---|---|
--db <DB_NAME> | Required. The D1 binding name. |
--local | Query the local D1 database. |
--remote | Query the Cloudflare-hosted D1 database. |
Example
bash
npx @orphnet/d1-eloquent status --db MY_DB --localExample output:
Migration Status Applied At
----------------------------------------- ------- --------------------
20240101_000000_create_users_table.ts APPLIED 2024-01-15 10:23:41
20240102_000000_create_posts_table.ts APPLIED 2024-01-15 10:23:42
20240110_000000_add_soft_deletes_to_posts.ts PENDING —