Added custom console Application class with migrations
This commit is contained in:
parent
9e3a344c17
commit
d78f9f0e5f
19 changed files with 85 additions and 116 deletions
68
src/PHPCensor/Console/Application.php
Normal file
68
src/PHPCensor/Console/Application.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Console;
|
||||
|
||||
use b8\Config;
|
||||
use Symfony\Component\Console\Application as BaseApplication;
|
||||
use Phinx\Console\Command\Create;
|
||||
use Phinx\Console\Command\Migrate;
|
||||
use Phinx\Console\Command\Rollback;
|
||||
use Phinx\Console\Command\Status;
|
||||
use Phinx\Config\Config as PhinxConfig;
|
||||
|
||||
class Application extends BaseApplication
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The name of the application
|
||||
* @param string $version The version of the application
|
||||
*/
|
||||
public function __construct($name = 'PHP Censor - Continuous Integration for PHP', $version = '')
|
||||
{
|
||||
parent::__construct($name, $version);
|
||||
|
||||
$applicationConfig = Config::getInstance();
|
||||
$databaseSettings = $applicationConfig->get('b8.database', []);
|
||||
|
||||
$phinxSettings = [
|
||||
'paths' => [
|
||||
'migrations' => 'src/PHPCensor/Migrations',
|
||||
],
|
||||
'environments' => [
|
||||
'default_migration_table' => 'migration',
|
||||
'default_database' => 'php-censor',
|
||||
'php-censor' => [
|
||||
'adapter' => 'mysql',
|
||||
'host' => $databaseSettings['servers']['write'],
|
||||
'name' => $databaseSettings['name'],
|
||||
'user' => $databaseSettings['username'],
|
||||
'pass' => $databaseSettings['password'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$phinxConfig = new PhinxConfig($phinxSettings);
|
||||
|
||||
$this->add(
|
||||
(new Create())
|
||||
->setConfig($phinxConfig)
|
||||
->setName('php-censor-migrations:create')
|
||||
);
|
||||
$this->add(
|
||||
(new Migrate())
|
||||
->setConfig($phinxConfig)
|
||||
->setName('php-censor-migrations:migrate')
|
||||
);
|
||||
$this->add(
|
||||
(new Rollback())
|
||||
->setConfig($phinxConfig)
|
||||
->setName('php-censor-migrations:rollback')
|
||||
);
|
||||
$this->add(
|
||||
(new Status())
|
||||
->setConfig($phinxConfig)
|
||||
->setName('php-censor-migrations:status')
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue