<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20230315164400 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add department field to the ticket_topic table';
}
public function up(Schema $schema): void
{
$this->skipIf(
true === $schema->getTable('ticket_topic')->hasColumn('department_id'),
'The department_id field already exists in the ticket_topic table!'
);
$schema->getTable('ticket_topic')
->addColumn('department_id', Types::STRING, [
'length' => 255,
])
->setNotnull(false);
$schema->getTable('ticket_topic')->addForeignKeyConstraint(
$schema->getTable('department'),
['department_id'],
['id'],
[],
'fk_department_ticket_topic'
);
}
public function down(Schema $schema): void
{
$this->skipIf(
false === $schema->getTable('ticket_topic')->hasColumn('department_id'),
'The department is already removed from the ticket_topic table!'
);
$schema->getTable('ticket_topic')
->dropColumn('department_id');
}
}