php-censor/src/PHPCensor/Migrations/20170321131931_add_environment.php
2017-03-26 17:36:30 +07:00

53 lines
1.2 KiB
PHP

<?php
use Phinx\Migration\AbstractMigration;
class AddEnvironment extends AbstractMigration
{
public function up()
{
$table = $this->table('environment');
if (!$this->hasTable('environment')) {
$table->create();
}
if (!$table->hasColumn('project_id')) {
$table->addColumn('project_id', 'integer')->save();
}
if (!$table->hasColumn('name')) {
$table->addColumn('name', 'string', ['limit' => 20])->save();
}
if (!$table->hasColumn('branches')) {
$table->addColumn('branches', 'text')->save();
}
if (!$table->hasIndex(['project_id', 'name'])) {
$table->addIndex(['project_id', 'name'])->save();
}
$table = $this->table('build');
if (!$table->hasColumn('environment')) {
$table->addColumn('environment', 'string', ['limit' => 20])->save();
}
}
public function down()
{
$table = $this->table('environment');
if ($this->hasTable('environment')) {
$table->drop();
}
$table = $this->table('build');
if ($table->hasColumn('environment')) {
$table->removeColumn('environment')->save();
}
}
}