File: /home/timetracker.panomity.com/tm.old/Migrations/Version20191207120554.php
<?php
declare(strict_types=1);
/*
* This file is part of the TaskManagementBundle for Kimai 2.
* All rights reserved by Kevin Papst (www.kevinpapst.de).
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TaskManagementBundle\Migrations;
use App\Doctrine\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* @version 1.0
*/
final class Version20191207120554 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create the task management table';
}
public function up(Schema $schema): void
{
if (!$schema->hasTable('kimai2_tasks')) {
$tasks = $schema->createTable('kimai2_tasks');
$tasks->addColumn('id', 'integer', ['autoincrement' => true, 'notnull' => true]);
$tasks->addColumn('title', 'string', ['notnull' => true, 'length' => 100]);
$tasks->addColumn('description', 'text', ['notnull' => false]);
$tasks->addColumn('status', 'string', ['notnull' => true, 'length' => 20]);
$tasks->addColumn('start_time', 'datetime', ['notnull' => false, 'comment' => '(DC2Type:datetime)']);
$tasks->addColumn('end_time', 'datetime', ['notnull' => false, 'comment' => '(DC2Type:datetime)']);
$tasks->addColumn('timezone', 'string', ['notnull' => false, 'length' => 64]);
$tasks->addColumn('activity_id', 'integer', ['notnull' => true]);
$tasks->addColumn('project_id', 'integer', ['notnull' => true]);
$tasks->addColumn('user_id', 'integer', ['notnull' => false]);
$tasks->addColumn('team_id', 'integer', ['notnull' => false]);
$tasks->setPrimaryKey(['id']);
$tasks->addIndex(['user_id', 'status', 'start_time', 'end_time']);
$tasks->addIndex(['team_id', 'status', 'start_time', 'end_time']);
$tasks->addForeignKeyConstraint('kimai2_users', ['user_id'], ['id'], ['onDelete' => 'CASCADE']);
$tasks->addForeignKeyConstraint('kimai2_activities', ['activity_id'], ['id'], ['onDelete' => 'CASCADE']);
$tasks->addForeignKeyConstraint('kimai2_projects', ['project_id'], ['id'], ['onDelete' => 'CASCADE']);
$tasks->addForeignKeyConstraint('kimai2_teams', ['team_id'], ['id'], ['onDelete' => 'CASCADE']);
}
if (!$schema->hasTable('kimai2_task_tags')) {
$tags = $schema->createTable('kimai2_task_tags');
$tags->addColumn('task_id', 'integer', ['length' => 11, 'notnull' => true]);
$tags->addColumn('tag_id', 'integer', ['length' => 11, 'notnull' => true]);
$tags->addIndex(['task_id']);
$tags->addIndex(['tag_id']);
$tags->setPrimaryKey(['task_id', 'tag_id']);
$tags->addForeignKeyConstraint('kimai2_tasks', ['task_id'], ['id'], ['onDelete' => 'CASCADE']);
$tags->addForeignKeyConstraint('kimai2_tags', ['tag_id'], ['id'], ['onDelete' => 'CASCADE']);
}
if (!$schema->hasTable('kimai2_task_timesheets')) {
$timesheets = $schema->createTable('kimai2_task_timesheets');
$timesheets->addColumn('task_id', 'integer', ['length' => 11, 'notnull' => true]);
$timesheets->addColumn('timesheet_id', 'integer', ['length' => 11, 'notnull' => true]);
$timesheets->addIndex(['task_id']);
$timesheets->addUniqueIndex(['timesheet_id']);
$timesheets->setPrimaryKey(['task_id', 'timesheet_id']);
$timesheets->addForeignKeyConstraint('kimai2_tasks', ['task_id'], ['id'], ['onDelete' => 'CASCADE']);
$timesheets->addForeignKeyConstraint('kimai2_timesheet', ['timesheet_id'], ['id'], ['onDelete' => 'CASCADE']);
}
}
public function down(Schema $schema): void
{
if ($schema->hasTable('kimai2_task_tags')) {
$schema->getTable('kimai2_task_tags')->removeForeignKey('FK_24CB2E388DB60186');
$schema->dropTable('kimai2_task_tags');
}
if ($schema->hasTable('kimai2_task_timesheets')) {
$schema->getTable('kimai2_task_timesheets')->removeForeignKey('FK_734BF4748DB60186');
$schema->dropTable('kimai2_task_timesheets');
}
if ($schema->hasTable('kimai2_tasks')) {
$schema->dropTable('kimai2_tasks');
}
}
}