<?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 Version20251125000001 extends AbstractMigration
{
public function up(Schema $schema): void
{
// display_cart_noticeカラムが存在しない場合のみ追加
$displayCartNoticeExists = $this->connection->fetchOne(
"SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'dtb_school'
AND COLUMN_NAME = 'display_cart_notice'"
);
if ($displayCartNoticeExists == 0) {
$this->addSql("ALTER TABLE dtb_school ADD display_cart_notice BOOLEAN DEFAULT 0 NOT NULL");
}
// cart_notice_textカラムが存在しない場合のみ追加
$cartNoticeTextExists = $this->connection->fetchOne(
"SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'dtb_school'
AND COLUMN_NAME = 'cart_notice_text'"
);
if ($cartNoticeTextExists == 0) {
$this->addSql("ALTER TABLE dtb_school ADD cart_notice_text TEXT DEFAULT NULL");
}
}
public function down(Schema $schema): void
{
// display_cart_noticeカラムが存在する場合のみ削除
$displayCartNoticeExists = $this->connection->fetchOne(
"SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'dtb_school'
AND COLUMN_NAME = 'display_cart_notice'"
);
if ($displayCartNoticeExists > 0) {
$this->addSql("ALTER TABLE dtb_school DROP COLUMN display_cart_notice");
}
// cart_notice_textカラムが存在する場合のみ削除
$cartNoticeTextExists = $this->connection->fetchOne(
"SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'dtb_school'
AND COLUMN_NAME = 'cart_notice_text'"
);
if ($cartNoticeTextExists > 0) {
$this->addSql("ALTER TABLE dtb_school DROP COLUMN cart_notice_text");
}
}
}