migrations/Version20240306154320.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use App\Helper\String\StringHelper;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. /**
  8.  * Auto-generated Migration: Please modify to your needs!
  9.  */
  10. final class Version20240306154320 extends AbstractMigration
  11. {
  12.     public function getDescription(): string
  13.     {
  14.         return '';
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         // this up() migration is auto-generated, please modify it to your needs
  19.         $franchises $this->connection->fetchAllAssociative('SELECT id FROM franchise');
  20.         $this->addSql('CREATE TABLE `device` (id INT AUTO_INCREMENT NOT NULL, shop_id INT NOT NULL, token VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, enabled TINYINT(1) DEFAULT 1 NOT NULL, deleted TINYINT(1) DEFAULT 0 NOT NULL, deleted_at DATETIME DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, UNIQUE INDEX UNIQ_92FB68E5F37A13B (token), INDEX IDX_92FB68E4D16C4DD (shop_id), UNIQUE INDEX name_shop (shop_id, name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  21.         $this->addSql('ALTER TABLE `device` ADD CONSTRAINT FK_92FB68E4D16C4DD FOREIGN KEY (shop_id) REFERENCES shop (id)');
  22.         $this->addSql('ALTER TABLE franchise ADD token VARCHAR(255) DEFAULT NULL');
  23.         array_walk_recursive($franchises, function($f){
  24.             $this->addSql("UPDATE franchise SET `token`='" StringHelper::generateToken() . "' WHERE id=$f");
  25.         });
  26.         
  27.         $this->addSql('ALTER TABLE franchise MODIFY token VARCHAR(255) NOT NULL');
  28.         $this->addSql('CREATE UNIQUE INDEX UNIQ_66F6CE2A5F37A13B ON franchise (token)');
  29.         $this->addSql('CREATE UNIQUE INDEX UNIQ_AC6A4CA25F37A13B ON shop (token)');
  30.     }
  31.     public function down(Schema $schema): void
  32.     {
  33.         // this down() migration is auto-generated, please modify it to your needs
  34.         $this->addSql('ALTER TABLE `device` DROP FOREIGN KEY FK_92FB68E4D16C4DD');
  35.         $this->addSql('DROP TABLE `device`');
  36.         $this->addSql('DROP INDEX UNIQ_66F6CE2A5F37A13B ON franchise');
  37.         $this->addSql('DROP INDEX UNIQ_AC6A4CA25F37A13B ON shop');
  38.         $this->addSql('ALTER TABLE franchise DROP token');
  39.     }
  40. }