$ php composer.phar require robmorgan/phinx
$ php composer.phar install
$ vendor/bin/phinx
Available commands:
breakpoint Manage breakpoints
create Create a new migration
help Displays help for a command
init Initialize the application for Phinx
list Lists commands
migrate Migrate the database
rollback Rollback the last or to a specific migration
status Show migration status
test Verify the configuration file
seed
seed:create Create a new database seeder
seed:run Run database seeders
$ vendor/bin/phinx list
paths:
migrations: "%%PHINX_CONFIG_DIR%%/config/migration"
environments:
default_migration_table: phinx_migration
default_database: dev
dev:
adapter: mysql
host: localhost
name: dev_db
user: user
pass: password
port: 3306
test:
adapter: mysql
host: localhost
name: test_db
user: user
pass: password
port: 3306
$ vendor/bin/phinx create MyFirstMigration
config/migration/20180912213646_my_first_migration.php
<?php
use Phinx\Migration\AbstractMigration;
class MyFirstMigration extends AbstractMigration
{
}
<?php
use Phinx\Migration\AbstractMigration;
class MyFirstMigration extends AbstractMigration
{
public function change()
{
// create the table
$table = $this->table('new_table');
$table->addColumn('new_table_id', 'integer')
->addColumn('created', 'datetime')
->create();
}
}
<?php
use Phinx\Migration\AbstractMigration;
class MyFirstMigration extends AbstractMigration
{
public function up(): void
{
$this->execute('
ALTER TABLE `new_table`
ADD COLUMN `new_column` VARCHAR(255) NULL AFTER `new_table_id`;
');
}
public function down(): void
{
$this->execute('
ALTER TABLE `new_table`
DROP COLUMN `new_column`;
');
}
}
$ phinx migrate -e dev
$ phinx migrate -e dev -t 20110103081132
$ phinx rollback -e dev
$ phinx rollback -e dev -t 20120103083322
$ phinx rollback -e development -d 2012
$ phinx rollback -e development -d 201201
$ phinx rollback -e development -d 20120103
$ phinx status -e dev