migrations/Version20230602170101.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 Version20230602170101 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.             false === $schema->getTable('health_mutual')->hasColumn('is_removed'),
  17.             'The is_removed field already removed from the health_mutual table!'
  18.         );
  19.         $schema->getTable('health_mutual')->dropColumn('is_removed');
  20.     }
  21.     public function down(Schema $schema): void
  22.     {
  23.         $this->skipIf(
  24.             true === $schema->getTable('health_mutual')->hasColumn('is_removed'),
  25.             'The is_removed is already set in the health_mutual table!'
  26.         );
  27.         $schema->getTable('health_mutual')
  28.             ->addColumn('is_removed'Types::BOOLEAN, ['notnull' => true'default' => false]);
  29.     }
  30.     public function postDown(Schema $schema): void
  31.     {
  32.         $this->connection->executeQuery('UPDATE health_mutual SET is_removed=0 WHERE is_enabled=1');
  33.         $this->connection->executeQuery('UPDATE health_mutual SET is_removed=1 WHERE is_enabled=0');
  34.     }
  35. }