<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20261011120000 extends AbstractMigration
{
public function getDescription(): string
{
return "Cache Google's weekday lines on the restaurant instead of decoding placeDetails on every read";
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE restaurante ADD opening_hours JSON DEFAULT NULL');
// Backfill from the stored Places Details responses. Rows whose placeDetails is not
// valid JSON, or has no weekday_text array, stay NULL, meaning "no Google hours".
$this->addSql(<<<'SQL'
UPDATE restaurante
SET opening_hours = JSON_EXTRACT(placeDetails, '$.result.opening_hours.weekday_text')
WHERE placeDetails IS NOT NULL
AND JSON_VALID(placeDetails)
AND JSON_TYPE(JSON_EXTRACT(placeDetails, '$.result.opening_hours.weekday_text')) = 'ARRAY'
SQL);
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE restaurante DROP opening_hours');
}
}