migrations/Version20230315164400.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\Migrations\AbstractMigration;
  7. final class Version20230315164400 extends AbstractMigration
  8. {
  9.     public function getDescription(): string
  10.     {
  11.         return 'Add department field to the ticket_topic table';
  12.     }
  13.     public function up(Schema $schema): void
  14.     {
  15.         $this->skipIf(
  16.             true === $schema->getTable('ticket_topic')->hasColumn('department_id'),
  17.             'The department_id field already exists in the ticket_topic table!'
  18.         );
  19.         $schema->getTable('ticket_topic')
  20.             ->addColumn('department_id'Types::STRING, [
  21.                 'length' => 255,
  22.             ])
  23.             ->setNotnull(false);
  24.         $schema->getTable('ticket_topic')->addForeignKeyConstraint(
  25.             $schema->getTable('department'),
  26.             ['department_id'],
  27.             ['id'],
  28.             [],
  29.             'fk_department_ticket_topic'
  30.         );
  31.     }
  32.     public function down(Schema $schema): void
  33.     {
  34.         $this->skipIf(
  35.             false === $schema->getTable('ticket_topic')->hasColumn('department_id'),
  36.             'The department is already removed from the ticket_topic table!'
  37.         );
  38.         $schema->getTable('ticket_topic')
  39.             ->dropColumn('department_id');
  40.     }
  41. }