Skip to main content
Aeros uses Phinx for database migrations and seeding. The CLI provides convenient wrapper commands for common database operations.

db:migrate

Runs all pending database migrations.
php aeros db:migrate
Options:
  • --environment=<env> - Specify the environment (development, staging, production)
  • --withSeeds - Run all seeders after migrations
  • --seed=<seeder> - Run specific seeders (can be used multiple times)
Examples:
php aeros db:migrate
# Runs all pending migrations
The db:migrate command automatically creates the app/Database/migrations/ and app/Database/seeds/ directories if they don’t exist.

run:database

Sets up and creates database environments. This command is useful for initial database configuration.
php aeros run:database
Options:
  • -c, --create - Create the database
  • -e, --seed - Seed the database after creation
  • -d, --development=<name> - Create development database with specified name
  • -s, --staging=<name> - Create staging database with specified name
  • -p, --production=<name> - Create production database with specified name
  • -a, --all - Create all environment databases (prompts for base name)
Examples:
php aeros run:database --create --development=myapp_dev
# Creates development database and updates .env

Supported Database Drivers

The command supports multiple database systems:
# Creates database with:
CREATE DATABASE IF NOT EXISTS `database_name`
# Checks if database exists, then creates:
CREATE DATABASE "database_name"
# Database file created automatically on connection
# Creates database with:
IF NOT EXISTS (SELECT name FROM sys.databases 
  WHERE name = N'database_name') 
CREATE DATABASE [database_name]

Configuration Updates

The run:database command automatically:
  1. Updates .env file with DB_DATABASE value
  2. Creates phinx.json if it doesn’t exist
  3. Updates phinx.json with environment-specific database names
If the database already exists, the command will display a warning but won’t overwrite it.

Creating Migrations and Seeders

While you can use Phinx commands directly, Aeros provides convenient make commands:

Create Migration

php aeros make:migration CreateUsersTable
See make:migration for more details.

Create Seeder

php aeros make:seed UserSeeder
See make:seed for more details.

Combined Approach

You can create both a migration and seeder in one command:
php aeros make:migration CreatePostsTable --seeder=PostSeeder

Database Workflow

Here’s a typical database workflow when starting a new Aeros project:
1

Configure Database

Set up your database connection in .env:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=aeros_app
DB_USERNAME=root
DB_PASSWORD=secret
2

Create Database

Use run:database to create your databases:
php aeros run:database --create --all
3

Create Migrations

Generate migration files for your tables:
php aeros make:migration CreateUsersTable
php aeros make:migration CreatePostsTable
4

Edit Migrations

Customize the generated migration files in app/Database/migrations/
5

Run Migrations

Execute your migrations:
php aeros db:migrate
6

Create Seeders (Optional)

Generate seeder files:
php aeros make:seed UserSeeder
7

Run Seeders (Optional)

Populate your database:
php aeros db:migrate --withSeeds

Direct Phinx Usage

You can also use Phinx commands directly if needed:
# Rollback last migration
./vendor/bin/phinx rollback

# View migration status
./vendor/bin/phinx status

# Run specific seeder
./vendor/bin/phinx seed:run -s UserSeeder
Refer to the Phinx documentation for advanced migration features.

Troubleshooting

The db:migrate command automatically creates missing directories. If you see this error, ensure your application has write permissions.
Verify your .env database configuration and ensure the database server is running.
Run php aeros run:database -c -a to generate the configuration file.
Ensure your database user has CREATE DATABASE privileges.

Next Steps

Make Commands

Learn about scaffolding migrations and seeders

Database Usage

Learn how to use the database in your application

Build docs developers (and LLMs) love