migrations/Version20230215181002.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. use PaperKite\Common\Entity\Enum\DossierTypeCategoryEnumType;
  7. use Symfony\Component\Uid\Uuid;
  8. final class Version20230215181002 extends AbstractMigration
  9. {
  10.     public function getDescription(): string
  11.     {
  12.         return 'Fill in dossier type values';
  13.     }
  14.     public function up(Schema $schema): void
  15.     {
  16.         $this->skipIf(
  17.             false === $schema->hasTable('dossier_type')
  18.             ||
  19.             $this->connection->executeQuery('SELECT COUNT(*) FROM dossier_type')->fetchOne(),
  20.             'The dossier_type table does not exists or is not empty!'
  21.         );
  22.         foreach (DossierTypeCategoryEnumType::getValues() as $value) {
  23.             $statement $this->connection->prepare(
  24.                 'INSERT INTO dossier_type (id, name, internal_id, category) VALUES (:id, :value, :value, :value);'
  25.             );
  26.             $statement->bindValue('id'Uuid::v4());
  27.             $statement->bindValue('value'$value);
  28.             $statement->executeQuery();
  29.         }
  30.     }
  31.     public function down(Schema $schema): void
  32.     {
  33.     }
  34. }