migrations/Version20230116130712.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 Version20230116130712 extends AbstractMigration
  8. {
  9.     public function getDescription(): string
  10.     {
  11.         return 'Add status to ticket';
  12.     }
  13.     public function up(Schema $schema): void
  14.     {
  15.         $this->skipIf(
  16.             true === $schema->getTable('ticket')->hasColumn('status'),
  17.             'The status field already exists in the ticket table!'
  18.         );
  19.         $schema->getTable('ticket')
  20.             ->addColumn('status'Types::STRING, ['length' => 20])
  21.             ->setNotnull(false);
  22.     }
  23.     public function postUp(Schema $schema): void
  24.     {
  25.         $this->connection->executeQuery(
  26.             "UPDATE ticket set status='new'"
  27.         );
  28.     }
  29.     public function down(Schema $schema): void
  30.     {
  31.         $this->skipIf(
  32.             false === $schema->getTable('ticket')->hasColumn('status'),
  33.             'The status is already removed from the ticket table!'
  34.         );
  35.         $schema->getTable('ticket')
  36.             ->dropColumn('status');
  37.     }
  38. }