migrations/Version20221111111706.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. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20221111111706 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'Correct data after deployment';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $duplicateNames $this->connection->executeQuery(
  19.             'SELECT COUNT(s.id) as nb, s.registration as school_registration
  20.                 FROM school s
  21.                 group by school_registration
  22.                 having nb > 1'
  23.         )->fetchAllAssociative();
  24.         foreach ($duplicateNames as $item) {
  25.             $registration $item['school_registration'];
  26.             $ids $this->connection->executeQuery('SELECT s2.id FROM school s2 WHERE s2.registration = ?', [$registration])
  27.                 ->fetchAllAssociative();
  28.             foreach ($ids as $id) {
  29.                 $this->addSql(
  30.                     'UPDATE school s1 SET s1.registration = ? WHERE s1.id = ?',
  31.                     [
  32.                         $registration '-d-' rand(0100),
  33.                         $id['id']
  34.                     ]
  35.                 );
  36.             }
  37.         }
  38.     }
  39.     public function down(Schema $schema): void
  40.     {
  41.         // this down() migration is auto-generated, please modify it to your needs
  42.     }
  43. }