Skip to content

Database Commands

Database commands manage PostgreSQL schema migrations and data seeding. FORGE generates numbered SQL migration files and Rust-compatible seeders that run in deterministic order.

forge migrate:run

Run all pending migrations against the connected database.

Usage

bash
forge migrate:run [OPTIONS]

Options

OptionTypeDefaultDescription
--verboseflagfalsePrint each SQL statement as it executes.

Example

bash
forge migrate:run --verbose
Running pending migrations...
  [1/3] 00014_create_contents_table    applied (12 ms)
  [2/3] 00015_create_menus_table       applied (8 ms)
  [3/3] 00016_migrate_media_polymorphic applied (15 ms)

All migrations applied successfully.

forge migrate:fresh

Drop every table in the database and re-run all migrations from scratch. Optionally seed the database afterward.

Usage

bash
forge migrate:fresh [OPTIONS]

Options

OptionTypeDefaultDescription
--seedflagfalseRun seeders after migrations complete.

DANGER

migrate:fresh destroys all data. It drops every table, including those not managed by FORGE. Never run this against a production database.

Example

bash
forge migrate:fresh --seed

forge migrate:status

Display a table showing which migrations have been applied and which are pending.

Usage

bash
forge migrate:status

Example Output

┌────┬──────────────────────────────────────────┬──────────┬─────────────────────┐
│ #  │ Migration                                │ Status   │ Applied At          │
├────┼──────────────────────────────────────────┼──────────┼─────────────────────┤
│  1 │ 00001_create_users_table                 │ Applied  │ 2025-04-10 08:12:03 │
│  2 │ 00002_create_roles_table                 │ Applied  │ 2025-04-10 08:12:03 │
│  3 │ 00003_create_permissions_table           │ Applied  │ 2025-04-10 08:12:03 │
│ .. │ ...                                      │ ...      │ ...                 │
│ 14 │ 00014_create_contents_table              │ Pending  │ —                   │
│ 15 │ 00015_create_menus_table                 │ Pending  │ —                   │
└────┴──────────────────────────────────────────┴──────────┴─────────────────────┘

forge migrate:rollback

Reverse the most recent batch of migrations, or roll back a specific number of steps.

Usage

bash
forge migrate:rollback [OPTIONS]

Options

OptionTypeDefaultDescription
--stepnumber1Number of migration steps to reverse.

WARNING

Rollback executes the down SQL for each migration in reverse order. Make sure your down migrations are tested before relying on this in staging or production.

Examples

bash
# Roll back the last migration
forge migrate:rollback

# Roll back the last 3 migrations
forge migrate:rollback --step 3

forge migrate:reset

Roll back every applied migration, leaving the database with only the _migrations tracking table.

Usage

bash
forge migrate:reset

DANGER

migrate:reset reverses all migrations. All data will be lost. This is equivalent to migrate:rollback --step <total>.


forge seed

Run database seeders to populate the database with initial or test data.

Usage

bash
forge seed [OPTIONS]

Options

OptionTypeDefaultDescription
--classstringRun a specific seeder by name instead of all seeders.
--refreshflagfalseTruncate all seeded tables before re-running seeders.

Examples

bash
# Run all seeders
forge seed

# Run a specific seeder
forge seed --class permissions

# Truncate and re-seed everything
forge seed --refresh

WARNING

The --refresh flag truncates tables in cascade order before re-seeding. Existing data in those tables will be deleted.


Common Workflows

Initial setup after cloning a project:

bash
forge migrate:run
forge seed

Reset everything during development:

bash
forge migrate:fresh --seed

Check what needs to run before deploying:

bash
forge migrate:status

See Also

Released under the MIT License.