migrations/Version20230127143058.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\Migrations\AbstractMigration;
  6. final class Version20230127143058 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Make messages_information not null';
  11.     }
  12.     public function preUp(Schema $schema): void
  13.     {
  14.         $this->connection->executeQuery(
  15.             "UPDATE message SET messages_information='[]' WHERE messages_information IS NULL"
  16.         );
  17.     }
  18.     public function up(Schema $schema): void
  19.     {
  20.         $this->skipIf(
  21.             true === $schema->getTable('message')->getColumn('messages_information')->getNotnull(),
  22.             'The messages_information field already not nullable in the message table!'
  23.         );
  24.         $schema->getTable('message')
  25.             ->getColumn('messages_information')
  26.             ->setNotnull(true);
  27.     }
  28.     public function down(Schema $schema): void
  29.     {
  30.         $this->skipIf(
  31.             false === $schema->getTable('message')->getColumn('messages_information')->getNotnull(),
  32.             'The messages_information field already nullable in the message table!'
  33.         );
  34.         $schema->getTable('message')
  35.             ->getColumn('messages_information')
  36.             ->setNotnull(false);
  37.     }
  38. }