app/DoctrineMigrations/Version20251125000000.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of EC-CUBE
  5.  *
  6.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  7.  *
  8.  * http://www.ec-cube.co.jp/
  9.  *
  10.  * For the full copyright and license information, please view the LICENSE
  11.  * file that was distributed with this source code.
  12.  */
  13. namespace DoctrineMigrations;
  14. use Doctrine\DBAL\Schema\Schema;
  15. use Doctrine\Migrations\AbstractMigration;
  16. /**
  17.  * 学校マスターに注意書き表示フラグとテキストを追加
  18.  */
  19. final class Version20251125000000 extends AbstractMigration
  20. {
  21.     public function up(Schema $schema): void
  22.     {
  23.         // display_noticeカラムが存在しない場合のみ追加
  24.         $displayNoticeExists $this->connection->fetchOne(
  25.             "SELECT COUNT(*) FROM information_schema.COLUMNS 
  26.              WHERE TABLE_SCHEMA = DATABASE() 
  27.              AND TABLE_NAME = 'dtb_school' 
  28.              AND COLUMN_NAME = 'display_notice'"
  29.         );
  30.         
  31.         if ($displayNoticeExists == 0) {
  32.             $this->addSql("ALTER TABLE dtb_school ADD display_notice BOOLEAN DEFAULT 0 NOT NULL");
  33.         }
  34.         
  35.         // notice_textカラムが存在しない場合のみ追加
  36.         $noticeTextExists $this->connection->fetchOne(
  37.             "SELECT COUNT(*) FROM information_schema.COLUMNS 
  38.              WHERE TABLE_SCHEMA = DATABASE() 
  39.              AND TABLE_NAME = 'dtb_school' 
  40.              AND COLUMN_NAME = 'notice_text'"
  41.         );
  42.         
  43.         if ($noticeTextExists == 0) {
  44.             $this->addSql("ALTER TABLE dtb_school ADD notice_text TEXT DEFAULT NULL");
  45.         }
  46.     }
  47.     public function down(Schema $schema): void
  48.     {
  49.         // display_noticeカラムが存在する場合のみ削除
  50.         $displayNoticeExists $this->connection->fetchOne(
  51.             "SELECT COUNT(*) FROM information_schema.COLUMNS 
  52.              WHERE TABLE_SCHEMA = DATABASE() 
  53.              AND TABLE_NAME = 'dtb_school' 
  54.              AND COLUMN_NAME = 'display_notice'"
  55.         );
  56.         
  57.         if ($displayNoticeExists 0) {
  58.             $this->addSql("ALTER TABLE dtb_school DROP COLUMN display_notice");
  59.         }
  60.         
  61.         // notice_textカラムが存在する場合のみ削除
  62.         $noticeTextExists $this->connection->fetchOne(
  63.             "SELECT COUNT(*) FROM information_schema.COLUMNS 
  64.              WHERE TABLE_SCHEMA = DATABASE() 
  65.              AND TABLE_NAME = 'dtb_school' 
  66.              AND COLUMN_NAME = 'notice_text'"
  67.         );
  68.         
  69.         if ($noticeTextExists 0) {
  70.             $this->addSql("ALTER TABLE dtb_school DROP COLUMN notice_text");
  71.         }
  72.     }
  73. }