php-censor/src/Migrations/20151008140800_add_project_groups.php

50 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2015-10-08 17:33:01 +02:00
<?php
use Phinx\Migration\AbstractMigration;
class AddProjectGroups extends AbstractMigration
{
2016-05-05 19:05:40 +02:00
public function up()
2015-10-08 17:33:01 +02:00
{
$table = $this->table('project_group');
2016-05-07 08:43:21 +02:00
2016-05-05 19:05:40 +02:00
if (!$this->hasTable('project_group')) {
$table->create();
}
2016-05-05 18:33:12 +02:00
if (!$table->hasColumn('title')) {
2017-01-29 03:49:43 +01:00
$table
->addColumn('title', 'string', ['limit' => 100, 'null' => false])
->save();
2016-05-05 18:33:12 +02:00
}
2015-10-08 17:33:01 +02:00
$table = $this->table('project');
2016-05-07 08:43:21 +02:00
2016-05-05 18:33:12 +02:00
if (!$table->hasColumn('group_id')) {
2016-05-07 08:43:21 +02:00
$table->addColumn('group_id', 'integer', ['signed' => true, 'null' => false, 'default' => 1,])->save();
}
if (!$table->hasForeignKey('group_id')) {
2016-05-05 18:33:12 +02:00
$table->addForeignKey('group_id', 'project_group', 'id', ['delete'=> 'RESTRICT', 'update' => 'CASCADE'])->save();
}
2015-10-08 17:33:01 +02:00
}
2016-05-05 19:05:40 +02:00
public function down()
{
2016-05-07 08:43:21 +02:00
$table = $this->table('project');
if ($table->hasForeignKey('group_id')) {
$table->dropForeignKey('group_id');
2016-05-05 19:05:40 +02:00
}
if ($table->hasColumn('group_id')) {
$table->removeColumn('group_id');
}
2016-05-07 08:43:21 +02:00
$table = $this->table('project_group');
if ($this->hasTable('project_group')) {
$table->drop();
}
2016-05-05 19:05:40 +02:00
}
2015-10-08 17:33:01 +02:00
}