Create and run database migrations for the PHP backend. Supports create, run, and rollback.
Create or run database migrations. Accepts $ARGUMENTS for the action.
/db-migrate create_users_table — create a new migration file/db-migrate run — execute all pending migrations/db-migrate rollback — revert the last migration/db-migrate status — show migration status$ARGUMENTS is a migration name):Generate a migration file at backend/migrations/{timestamp}_{name}.php
YYYYMMDD_HHMMSSbackend/migrations/20260306_120000_create_users_table.phpMigration file template:
<?php
declare(strict_types=1);
return new class {
public function up(PDO $db): void
{
$db->exec("
CREATE TABLE table_name (
id INT AUTO_INCREMENT PRIMARY KEY,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)
");
}
public function down(PDO $db): void
{
$db->exec("DROP TABLE IF EXISTS table_name");
}
};
Follow conventions:
users, orders, order_items)id, created_at, updated_atdeleted_at TIMESTAMP NULL) where appropriate$ARGUMENTS is "run"):cd backend && php migrate.php run
$ARGUMENTS is "rollback"):cd backend && php migrate.php rollback
$ARGUMENTS is "status"):cd backend && php migrate.php status