migrations/Version20261011120000.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 Version20261011120000 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return "Cache Google's weekday lines on the restaurant instead of decoding placeDetails on every read";
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql('ALTER TABLE restaurante ADD opening_hours JSON DEFAULT NULL');
  15.         // Backfill from the stored Places Details responses. Rows whose placeDetails is not
  16.         // valid JSON, or has no weekday_text array, stay NULL, meaning "no Google hours".
  17.         $this->addSql(<<<'SQL'
  18.             UPDATE restaurante
  19.             SET opening_hours = JSON_EXTRACT(placeDetails, '$.result.opening_hours.weekday_text')
  20.             WHERE placeDetails IS NOT NULL
  21.               AND JSON_VALID(placeDetails)
  22.               AND JSON_TYPE(JSON_EXTRACT(placeDetails, '$.result.opening_hours.weekday_text')) = 'ARRAY'
  23.             SQL);
  24.     }
  25.     public function down(Schema $schema): void
  26.     {
  27.         $this->addSql('ALTER TABLE restaurante DROP opening_hours');
  28.     }
  29. }