Skip to content
Antares

Migrations

Antares ships its own migration system built on raw PDO, with no ORM required. It works independently of the Eloquent bridge or any other ORM you choose to use.

Migrations connect with these variables from .env (or the real environment, which wins):

VariableDefaultNotes
DB_DRIVERmysqlmysql, pgsql, sqlite, sqlsrv or oci (Oracle)
DB_HOST127.0.0.1Not used for SQLite
DB_PORTthe driver’s default3306, 5432, 1433 or 1521
DB_DATABASE(empty)Database name; the file path for SQLite; the service name for Oracle
DB_USERNAME(empty)
DB_PASSWORD(empty)
DB_CHARSETutf8mb4MySQL only
DB_DSN(none)A complete PDO connection string, used instead of all of the above except username and password

The connection string is built for each driver:

DB_DRIVERConnection string
mysqlmysql:host=…;port=…;dbname=…;charset=…
pgsqlpgsql:host=…;port=…;dbname=…
sqlitesqlite:{DB_DATABASE}
sqlsrvsqlsrv:Server={host},{port};Database=…
ocioci:dbname=//{host}:{port}/{service name}

PHP needs the matching PDO extension (pdo_mysql, pdo_pgsql, pdo_sqlite, pdo_sqlsrv or pdo_oci). Use DB_DSN for anything else, such as an Oracle TNS name:

DB_DRIVER=oci
DB_DSN="oci:dbname=PROD_TNS;charset=AL32UTF8"

The migrations table needs Oracle 12c or newer (it uses an identity column).


Terminal window
php vendor/bin/antares make:migration create_users_table

This creates a file in database/migrations/ with a timestamp prefix, e.g. 2026_01_15_103000_create_users_table.php. It contains a plain class (no namespace, no base class) whose name is the file name without the timestamp, in PascalCase:

<?php
declare(strict_types=1);
final class CreateUsersTable
{
public function up(\PDO $pdo): void
{
$pdo->exec("
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
");
}
public function down(\PDO $pdo): void
{
$pdo->exec("DROP TABLE IF EXISTS users");
}
}

Keep the class name and file name in sync: the runner derives the class name from the file name. Class names must be unique across all migrations.


Run all pending migrations:

Terminal window
php vendor/bin/antares migrate

Migrations are tracked in a migrations table by file name. Already-run migrations are skipped, and everything run together is recorded as one batch.


Roll back the last batch of migrations:

Terminal window
php vendor/bin/antares migrate:rollback

Migrations in the last batch are rolled back in reverse order, calling each migration’s down() method.


  • Migration files live in database/migrations/ (relative to where you run the command, normally the project root)
  • Files are sorted by name, so the timestamp prefix sets the order
  • The migrations table is created automatically on first run
  • Each migration receives a raw PDO instance, set to throw exceptions on errors
  • Migrations are not wrapped in a transaction: if one fails halfway, the ones before it stay applied and recorded

Migrations use raw PDO directly, so they work regardless of which ORM you use. Pair them with the Eloquent bridge, use a different ORM, or skip an ORM entirely.