migrations/Version20260407173147.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 Version20260407173147 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Convert phone numbers from format (0xxxxx/+xxxxx) to international format (0033xxxx/00xxxx)';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql("UPDATE user SET phone = CONCAT('0033', SUBSTRING(phone, 2)) WHERE phone LIKE '0%' AND phone NOT LIKE '0033%'");
  15.         $this->addSql("UPDATE user SET phone = CONCAT('00', SUBSTRING(phone, 2)) WHERE phone LIKE '+%'");
  16.     }
  17.     public function down(Schema $schema): void
  18.     {
  19.         $this->addSql("UPDATE user SET phone = CONCAT('+', SUBSTRING(phone, 3)) WHERE phone LIKE '0%' AND phone NOT LIKE '0033%'");
  20.         $this->addSql("UPDATE user SET phone = CONCAT('0', SUBSTRING(phone, 5)) WHERE phone LIKE '0033%'");
  21.     }
  22. }