migrations/Version20221222113506.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\Migrations\AbstractMigration;
  6. final class Version20221222113506 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Add short_code and export_id to health_insurance';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->skipIf(
  15.             true === $schema->getTable('health_insurance')->hasIndex('uniq_health_insurance_short_code'),
  16.             'The short_code field already exists in the health_insurance table!'
  17.         );
  18.         $schema->getTable('health_insurance')
  19.             ->getColumn('short_code')
  20.             ->setNotnull(true);
  21.         $schema->getTable('health_insurance')->addIndex(
  22.             ['short_code'],
  23.             'uniq_health_insurance_short_code'
  24.         );
  25.         $schema->getTable('health_insurance')
  26.             ->getColumn('export_id')
  27.             ->setNotnull(true);
  28.         $schema->getTable('health_insurance')->addIndex(
  29.             ['export_id'],
  30.             'uniq_health_insurance_export_id'
  31.         );
  32.     }
  33.     public function down(Schema $schema): void
  34.     {
  35.         $this->skipIf(
  36.             false === $schema->getTable('health_insurance')->hasIndex('uniq_health_insurance_short_code'),
  37.             'The short_code field already exists in the health_insurance table!'
  38.         );
  39.         $schema->getTable('health_insurance')->dropIndex('uniq_health_insurance_short_code');
  40.         $schema->getTable('health_insurance')->dropIndex('uniq_health_insurance_export_id');
  41.     }
  42. }