<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use App\Helper\String\StringHelper;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240306154320 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$franchises = $this->connection->fetchAllAssociative('SELECT id FROM franchise');
$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');
$this->addSql('ALTER TABLE `device` ADD CONSTRAINT FK_92FB68E4D16C4DD FOREIGN KEY (shop_id) REFERENCES shop (id)');
$this->addSql('ALTER TABLE franchise ADD token VARCHAR(255) DEFAULT NULL');
array_walk_recursive($franchises, function($f){
$this->addSql("UPDATE franchise SET `token`='" . StringHelper::generateToken() . "' WHERE id=$f");
});
$this->addSql('ALTER TABLE franchise MODIFY token VARCHAR(255) NOT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_66F6CE2A5F37A13B ON franchise (token)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_AC6A4CA25F37A13B ON shop (token)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE `device` DROP FOREIGN KEY FK_92FB68E4D16C4DD');
$this->addSql('DROP TABLE `device`');
$this->addSql('DROP INDEX UNIQ_66F6CE2A5F37A13B ON franchise');
$this->addSql('DROP INDEX UNIQ_AC6A4CA25F37A13B ON shop');
$this->addSql('ALTER TABLE franchise DROP token');
}
}