migrations/Version20250126191827.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use App\Tools\Utils;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. /**
  8.  * Auto-generated Migration: Please modify to your needs!
  9.  */
  10. final class Version20250126191827 extends AbstractMigration
  11. {
  12.     public function getDescription(): string
  13.     {
  14.         return '';
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         $this->addSql('ALTER TABLE country ADD sanitized_name VARCHAR(255) NULL');
  19.         $countries $this->connection->fetchAllAssociative('SELECT id, name FROM country');
  20.         foreach ($countries as $country) {
  21.             $this->addSql('UPDATE country SET sanitized_name = ? WHERE id = ?', [
  22.                 Utils::sanitizeName($country['name']),
  23.                 $country['id']]
  24.             );
  25.         }
  26.     }
  27.     public function down(Schema $schema): void
  28.     {
  29.         $this->addSql('ALTER TABLE country DROP sanitized_name');
  30.     }
  31. }