<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20250326145546 extends AbstractMigration
{
public function getDescription(): string
{
return 'Prefix deleted users email with delete-timestamp';
}
public function up(Schema $schema): void
{
$this->addSql("
UPDATE user
SET
email = CONCAT('deleted-', UNIX_TIMESTAMP(deleted_at), '-', email),
username = CONCAT('deleted-', UNIX_TIMESTAMP(deleted_at), '-', username)
WHERE deleted_at IS NOT NULL
AND email NOT LIKE 'deleted-%'
AND username NOT LIKE 'deleted-%'
AND discr = 'shopmanager';
");
}
public function down(Schema $schema): void
{
$this->addSql("
UPDATE user
SET
email = SUBSTRING(email, LOCATE('-', email, 9) + 1),
username = SUBSTRING(username, LOCATE('-', username, 9) + 1)
WHERE deleted_at IS NOT NULL
AND email LIKE 'deleted-%'
AND username LIKE 'deleted-%'
AND discr = 'shopmanager';
");
}
}