migrations/Version20260616120000.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 Version20260616120000 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Allow one customer and one staff account per email.';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql("ALTER TABLE user ADD account_type VARCHAR(20) DEFAULT 'staff' NOT NULL");
  15.         $this->addSql("UPDATE user SET account_type = 'customer' WHERE discr = 'customer'");
  16.         $this->addSql('DROP INDEX UNIQ_8D93D649E7927C74 ON user');
  17.         $this->addSql('CREATE UNIQUE INDEX UNIQ_USER_EMAIL_ACCOUNT_TYPE ON user (email, account_type)');
  18.     }
  19.     public function down(Schema $schema): void
  20.     {
  21.         $this->addSql('DROP INDEX UNIQ_USER_EMAIL_ACCOUNT_TYPE ON user');
  22.         $this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649E7927C74 ON user (email)');
  23.         $this->addSql('ALTER TABLE user DROP account_type');
  24.     }
  25. }