migrations/Version20250326145546.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 Version20250326145546 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Prefix deleted users email with delete-timestamp';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql("
  15.             UPDATE user
  16.             SET
  17.                 email = CONCAT('deleted-', UNIX_TIMESTAMP(deleted_at), '-', email),
  18.                 username = CONCAT('deleted-', UNIX_TIMESTAMP(deleted_at), '-', username)
  19.             WHERE deleted_at IS NOT NULL
  20.             AND email NOT LIKE 'deleted-%'
  21.             AND username NOT LIKE 'deleted-%'
  22.             AND discr = 'shopmanager';
  23.         ");
  24.     }
  25.     public function down(Schema $schema): void
  26.     {
  27.         $this->addSql("
  28.             UPDATE user
  29.             SET 
  30.                 email = SUBSTRING(email, LOCATE('-', email, 9) + 1),
  31.                 username = SUBSTRING(username, LOCATE('-', username, 9) + 1)
  32.             WHERE deleted_at IS NOT NULL
  33.             AND email LIKE 'deleted-%'
  34.             AND username LIKE 'deleted-%'
  35.             AND discr = 'shopmanager';
  36.         ");
  37.     }
  38. }