migrations/Version20250327103122.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 Version20250327103122 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Manage pairing devices';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql('CREATE TABLE pairing (id INT AUTO_INCREMENT NOT NULL, device_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, identifier VARCHAR(255) NOT NULL, model VARCHAR(255) DEFAULT NULL, version VARCHAR(255) DEFAULT NULL, ip VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX IDX_8816ECFC94A4C7D4 (device_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  15.         $this->addSql('ALTER TABLE pairing ADD CONSTRAINT FK_8816ECFC94A4C7D4 FOREIGN KEY (device_id) REFERENCES `device` (id)');
  16.         $this->addSql('ALTER TABLE device ADD pin INT DEFAULT NULL, ADD identifier VARCHAR(255) DEFAULT NULL');
  17.         $this->addSql('UPDATE device SET pin = LPAD(FLOOR(RAND() * 1000000), 6, "0") WHERE type = "kiosk"');
  18.     }
  19.     public function down(Schema $schema): void
  20.     {
  21.         $this->addSql('ALTER TABLE pairing DROP FOREIGN KEY FK_8816ECFC94A4C7D4');
  22.         $this->addSql('DROP TABLE pairing');
  23.         $this->addSql('ALTER TABLE `device` DROP pin, DROP identifier');
  24.     }
  25. }