Works with PHP 7.1+
You can run command 'migration_runner' for creating and applying or reverting migration to your database.
./vendor/bin/migration_runner <method>
By default, runner call method 'help'.
Available methods
- help - Show help information
- create {name} - Create new migration
- up {runCount=0} - Apply new migrations
- down {runCount=1} - Revert some migration
In your migrations you should use Phalcon Pdo Adapter provided by method 'getDbConnection'. You can find API definition in Phalcon documentation
public function up(): bool
{
$this->getDbConnection()->createTable('foo', null, [
'columns' => [
new \Phalcon\Db\Column('bar', [
'type' => \Phalcon\Db\Column::TYPE_INTEGER
])
]
]);
return true;
}
Create migration (For first run runner create config)
$ ./vendor/bin/migration_runner create new_migration
Enter database adapter (default: sqlite): sqlite
Enter database name (default: phalcon): test.db
Config generated in /my_project/migration_runner.config.php
Migration /my_project/migrations/m1522260172_new_migration.php created!
Describe your migration
<?php
use Phalcon\Db\Column;
use Vados\MigrationRunner\migration\Migration;
class m1522260172_new_migration extends Migration
{
public function up(): bool
{
$this->getDbConnection()->createTable('foo', null, [
'columns' => [
new Column('bar', [
'type' => Column::TYPE_INTEGER
])
]
]);
return true;
}
public function down(): bool
{
$this->getDbConnection()->dropTable('foo');
return true;
}
}
Apply your migration
$ ./migration_runner up
m1522260172_new_migration.php
Apply the above migrations? (yes|no) [yes]: yes
Migration m1522260172_new_migration.php: true
Use composer for installation
composer require vados/phalcon-migration-runner
- Writing tests
- Code review
- Guidelines accord