<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
use PaperKite\Common\DataFixtures\HealthInsuranceFixtures;
final class Version20230310094900 extends AbstractMigration
{
public function getDescription(): string
{
return 'update short_code to integer for health_insurance table';
}
public function up(Schema $schema): void
{
$this->skipIf(
Type::getType(Types::INTEGER) === $schema->getTable('health_insurance')->getColumn('export_id')->getType(),
'The export_id field is already integer in the health_insurance table!'
);
foreach (HealthInsuranceFixtures::getList() as $insurance) {
$query = $this->connection->prepare(
'UPDATE health_insurance SET name=:name, short_code=:short_code, export_id=:export_id, is_default=:is_default WHERE name=:name;'
);
$query->bindValue('name', $insurance['name']);
$query->bindValue('short_code', $insurance['shortCode']);
$query->bindValue('export_id', $insurance['exportId']);
$query->bindValue('is_default', (int) $insurance['isDefault']);
$query->executeQuery();
}
$schema->getTable('health_insurance')
->getColumn('export_id')
->setType(Type::getType(Types::INTEGER));
}
public function down(Schema $schema): void
{
$this->skipIf(
Type::getType(Types::STRING) === $schema->getTable('health_insurance')->getColumn('export_id')->getType(),
'The export_id field is already string in the health_insurance table!'
);
$schema->getTable('health_insurance')
->getColumn('export_id')
->setType(Type::getType(Types::STRING));
}
}