<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20230602170100 extends AbstractMigration
{
public function getDescription(): string
{
return 'Change is_removed to is_enabled field for the health_mutual table';
}
public function up(Schema $schema): void
{
$this->skipIf(
true === $schema->getTable('health_mutual')->hasColumn('is_enabled'),
'The is_enabled field already set in the health_mutual table!'
);
$schema->getTable('health_mutual')
->addColumn('is_enabled', Types::BOOLEAN, ['notnull' => true, 'default' => false]);
}
public function postUp(Schema $schema): void
{
$this->connection->executeQuery('UPDATE health_mutual SET is_enabled=0 WHERE is_removed=1');
$this->connection->executeQuery('UPDATE health_mutual SET is_enabled=1 WHERE is_removed=0');
}
public function down(Schema $schema): void
{
$this->skipIf(
false === $schema->getTable('health_mutual')->hasColumn('is_enabled'),
'The is_enabled is already removed from the health_mutual table!'
);
$schema->getTable('health_mutual')->dropColumn('is_enabled');
}
}