migrations/Version20230310094900.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\Type;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\Migrations\AbstractMigration;
  8. use PaperKite\Common\DataFixtures\HealthInsuranceFixtures;
  9. final class Version20230310094900 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'update short_code to integer for health_insurance table';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $this->skipIf(
  18.             Type::getType(Types::INTEGER) === $schema->getTable('health_insurance')->getColumn('export_id')->getType(),
  19.             'The export_id field is already integer in the health_insurance table!'
  20.         );
  21.         foreach (HealthInsuranceFixtures::getList() as $insurance) {
  22.             $query $this->connection->prepare(
  23.                 'UPDATE health_insurance SET name=:name, short_code=:short_code, export_id=:export_id, is_default=:is_default WHERE name=:name;'
  24.             );
  25.             $query->bindValue('name'$insurance['name']);
  26.             $query->bindValue('short_code'$insurance['shortCode']);
  27.             $query->bindValue('export_id'$insurance['exportId']);
  28.             $query->bindValue('is_default', (int) $insurance['isDefault']);
  29.             $query->executeQuery();
  30.         }
  31.         $schema->getTable('health_insurance')
  32.             ->getColumn('export_id')
  33.             ->setType(Type::getType(Types::INTEGER));
  34.     }
  35.     public function down(Schema $schema): void
  36.     {
  37.         $this->skipIf(
  38.             Type::getType(Types::STRING) === $schema->getTable('health_insurance')->getColumn('export_id')->getType(),
  39.             'The export_id field is already string in the health_insurance table!'
  40.         );
  41.         $schema->getTable('health_insurance')
  42.             ->getColumn('export_id')
  43.             ->setType(Type::getType(Types::STRING));
  44.     }
  45. }