migrations/Version20261018120000.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 Version20261018120000 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Add dish.tags (declared diet tags as a JSON list); existing dishes get no tags. DDL auto-commits: if this fails midway the dish.tags column may already exist (drop it and re-run)';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         // Three steps (add nullable, backfill, NOT NULL) because a JSON column cannot have a literal default, and an
  15.         // expression default would drift from the Doctrine mapping and is not portable to MariaDB/MySQL 5.7.
  16.         $this->addSql('ALTER TABLE dish ADD tags JSON DEFAULT NULL');
  17.         $this->addSql('UPDATE dish SET tags = JSON_ARRAY()');
  18.         $this->addSql('ALTER TABLE dish CHANGE tags tags JSON NOT NULL');
  19.     }
  20.     public function down(Schema $schema): void
  21.     {
  22.         $this->addSql('ALTER TABLE dish DROP tags');
  23.     }
  24. }