<?php
declare(strict_types=1);
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* 学校マスターに注意書き表示フラグとテキストを追加
*/
final class Version20251125000000 extends AbstractMigration
{
public function up(Schema $schema): void
{
// display_noticeカラムが存在しない場合のみ追加
$displayNoticeExists = $this->connection->fetchOne(
"SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'dtb_school'
AND COLUMN_NAME = 'display_notice'"
);
if ($displayNoticeExists == 0) {
$this->addSql("ALTER TABLE dtb_school ADD display_notice BOOLEAN DEFAULT 0 NOT NULL");
}
// notice_textカラムが存在しない場合のみ追加
$noticeTextExists = $this->connection->fetchOne(
"SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'dtb_school'
AND COLUMN_NAME = 'notice_text'"
);
if ($noticeTextExists == 0) {
$this->addSql("ALTER TABLE dtb_school ADD notice_text TEXT DEFAULT NULL");
}
}
public function down(Schema $schema): void
{
// display_noticeカラムが存在する場合のみ削除
$displayNoticeExists = $this->connection->fetchOne(
"SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'dtb_school'
AND COLUMN_NAME = 'display_notice'"
);
if ($displayNoticeExists > 0) {
$this->addSql("ALTER TABLE dtb_school DROP COLUMN display_notice");
}
// notice_textカラムが存在する場合のみ削除
$noticeTextExists = $this->connection->fetchOne(
"SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'dtb_school'
AND COLUMN_NAME = 'notice_text'"
);
if ($noticeTextExists > 0) {
$this->addSql("ALTER TABLE dtb_school DROP COLUMN notice_text");
}
}
}