migrations/Version20230602170100.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 Version20230602170100 extends AbstractMigration
  8. {
  9.     public function getDescription(): string
  10.     {
  11.         return 'Change is_removed to is_enabled field for the health_mutual table';
  12.     }
  13.     public function up(Schema $schema): void
  14.     {
  15.         $this->skipIf(
  16.             true === $schema->getTable('health_mutual')->hasColumn('is_enabled'),
  17.             'The is_enabled field already set in the health_mutual table!'
  18.         );
  19.         $schema->getTable('health_mutual')
  20.             ->addColumn('is_enabled'Types::BOOLEAN, ['notnull' => true'default' => false]);
  21.     }
  22.     public function postUp(Schema $schema): void
  23.     {
  24.         $this->connection->executeQuery('UPDATE health_mutual SET is_enabled=0 WHERE is_removed=1');
  25.         $this->connection->executeQuery('UPDATE health_mutual SET is_enabled=1 WHERE is_removed=0');
  26.     }
  27.     public function down(Schema $schema): void
  28.     {
  29.         $this->skipIf(
  30.             false === $schema->getTable('health_mutual')->hasColumn('is_enabled'),
  31.             'The is_enabled is already removed from the health_mutual table!'
  32.         );
  33.         $schema->getTable('health_mutual')->dropColumn('is_enabled');
  34.     }
  35. }