<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20261018120000 extends AbstractMigration
{
public function getDescription(): string
{
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)';
}
public function up(Schema $schema): void
{
// Three steps (add nullable, backfill, NOT NULL) because a JSON column cannot have a literal default, and an
// expression default would drift from the Doctrine mapping and is not portable to MariaDB/MySQL 5.7.
$this->addSql('ALTER TABLE dish ADD tags JSON DEFAULT NULL');
$this->addSql('UPDATE dish SET tags = JSON_ARRAY()');
$this->addSql('ALTER TABLE dish CHANGE tags tags JSON NOT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE dish DROP tags');
}
}