app/DoctrineMigrations/Version20261112000001.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. /**
  7.  * 会員メニュー(公式LINE・年間スケジュール表・出品リスト・マニュアル)用のカラムを dtb_base_info に追加.
  8.  *
  9.  * 既にカラムが存在する環境(schema:update 済み等)ではスキップする.
  10.  */
  11. final class Version20261112000001 extends AbstractMigration
  12. {
  13.     private const COLUMNS = [
  14.         'line_official_url' => 'VARCHAR(1024) DEFAULT NULL',
  15.         'annual_schedule_file' => 'VARCHAR(255) DEFAULT NULL',
  16.         'listing_list_file' => 'VARCHAR(255) DEFAULT NULL',
  17.         'manual_file' => 'VARCHAR(255) DEFAULT NULL',
  18.     ];
  19.     public function getDescription(): string
  20.     {
  21.         return 'Add member menu (official LINE URL / download files) columns to dtb_base_info';
  22.     }
  23.     public function up(Schema $schema): void
  24.     {
  25.         $table = $schema->getTable('dtb_base_info');
  26.         foreach (self::COLUMNS as $name => $definition) {
  27.             if (!$table->hasColumn($name)) {
  28.                 $this->addSql(sprintf('ALTER TABLE dtb_base_info ADD %s %s', $name, $definition));
  29.             }
  30.         }
  31.     }
  32.     public function down(Schema $schema): void
  33.     {
  34.         $table = $schema->getTable('dtb_base_info');
  35.         foreach (array_keys(self::COLUMNS) as $name) {
  36.             if ($table->hasColumn($name)) {
  37.                 $this->addSql(sprintf('ALTER TABLE dtb_base_info DROP %s', $name));
  38.             }
  39.         }
  40.     }
  41. }