app/DoctrineMigrations/Version20251211000000.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 Version20251211000000 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '学校マスターテーブルに削除フラグカラムを追加';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $sm $this->connection->createSchemaManager();
  18.         // dtb_school テーブルに del_flg カラムを追加
  19.         if ($sm->tablesExist(['dtb_school'])) {
  20.             $columns $sm->listTableColumns('dtb_school');
  21.             $columnNames array_map(function($column) {
  22.                 return $column->getName();
  23.             }, $columns);
  24.             if (!in_array('del_flg'$columnNames)) {
  25.                 $this->addSql('ALTER TABLE dtb_school ADD del_flg BOOLEAN NOT NULL DEFAULT FALSE');
  26.             }
  27.         }
  28.     }
  29.     public function down(Schema $schema): void
  30.     {
  31.         $sm $this->connection->createSchemaManager();
  32.         // dtb_school テーブルから del_flg カラムを削除
  33.         if ($sm->tablesExist(['dtb_school'])) {
  34.             $columns $sm->listTableColumns('dtb_school');
  35.             $columnNames array_map(function($column) {
  36.                 return $column->getName();
  37.             }, $columns);
  38.             if (in_array('del_flg'$columnNames)) {
  39.                 $this->addSql('ALTER TABLE dtb_school DROP COLUMN del_flg');
  40.             }
  41.         }
  42.     }
  43. }