app/DoctrineMigrations/Version20251021100000.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.  * 学校マスターにセット商品のサイズ(規格)表示フラグを追加
  8.  */
  9. final class Version20251021100000 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'dtb_schoolテーブルにreport_setproduct_size_flag(smallint)を追加 - セット商品のサイズ表示ON/OFF';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $schemaManager $this->connection->createSchemaManager();
  18.         if (!$schemaManager->tablesExist(['dtb_school'])) {
  19.             return;
  20.         }
  21.         $columns $schemaManager->listTableColumns('dtb_school');
  22.         $has false;
  23.         foreach ($columns as $column) {
  24.             if ($column->getName() === 'report_setproduct_size_flag') {
  25.                 $has true;
  26.                 break;
  27.             }
  28.         }
  29.         if (!$has) {
  30.             // デフォルトは1(表示)
  31.             $this->addSql('ALTER TABLE dtb_school ADD report_setproduct_size_flag SMALLINT UNSIGNED NULL DEFAULT 1');
  32.         }
  33.     }
  34.     public function down(Schema $schema): void
  35.     {
  36.         $schemaManager $this->connection->createSchemaManager();
  37.         if (!$schemaManager->tablesExist(['dtb_school'])) {
  38.             return;
  39.         }
  40.         $columns $schemaManager->listTableColumns('dtb_school');
  41.         $has false;
  42.         foreach ($columns as $column) {
  43.             if ($column->getName() === 'report_setproduct_size_flag') {
  44.                 $has true;
  45.                 break;
  46.             }
  47.         }
  48.         if ($has) {
  49.             $this->addSql('ALTER TABLE dtb_school DROP report_setproduct_size_flag');
  50.         }
  51.     }
  52. }