migrations/Version20240503153428.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 Version20240503153428 extends AbstractMigration
  8. {
  9.     public function getDescription(): string
  10.     {
  11.         return '';
  12.     }
  13.     public function up(Schema $schema): void
  14.     {
  15.         $this->skipIf(
  16.             true === $schema->getTable('cmcm_request')->hasColumn('ticket_id'),
  17.             'The ticket_id field was already added in the cmcm_request table!'
  18.         );
  19.         $schema->getTable('cmcm_request')->addColumn(
  20.             'ticket_id',
  21.             Types::STRING,
  22.             [
  23.                 'length' => 255,
  24.                 'notnull' => false,
  25.                 'default' => null,
  26.             ]
  27.         );
  28.         $schema->getTable('cmcm_request')->addForeignKeyConstraint(
  29.             'ticket',
  30.             ['ticket_id'],
  31.             ['id'],
  32.             [],
  33.             'fk_cmcm_request_ticket'
  34.         );
  35.     }
  36.     public function down(Schema $schema): void
  37.     {
  38.         $this->skipIf(
  39.             false === $schema->getTable('cmcm_request')->hasColumn('ticket_id'),
  40.             'The ticket_id field was already removed from the cmcm_request table!'
  41.         );
  42.         $schema->getTable('cmcm_request')->dropIndex('fk_cmcm_request_ticket');
  43.         $schema->getTable('cmcm_request')->dropColumn('ticket_id');
  44.     }
  45. }