<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* 商品詳細ページの注意書き機能を追加
*/
final class Version20251126100001 extends AbstractMigration
{
public function getDescription(): string
{
return 'dtb_schoolテーブルに商品詳細ページ用の注意書きフィールドを追加';
}
public function up(Schema $schema): void
{
// MySQLの場合のみ実行
if ($this->connection->getDatabasePlatform()->getName() !== 'mysql') {
return;
}
// display_product_notice カラムが存在しない場合のみ追加
$displayProductNoticeExists = $this->connection->fetchOne("
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'dtb_school'
AND COLUMN_NAME = 'display_product_notice'
");
if (!$displayProductNoticeExists) {
$this->addSql("
ALTER TABLE dtb_school
ADD display_product_notice BOOLEAN DEFAULT 0 NOT NULL
COMMENT '商品詳細ページに注意書きを表示するか'
");
}
// product_notice_text カラムが存在しない場合のみ追加
$productNoticeTextExists = $this->connection->fetchOne("
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'dtb_school'
AND COLUMN_NAME = 'product_notice_text'
");
if (!$productNoticeTextExists) {
$this->addSql("
ALTER TABLE dtb_school
ADD product_notice_text TEXT DEFAULT NULL
COMMENT '商品詳細ページに表示する注意書きテキスト'
");
}
}
public function down(Schema $schema): void
{
// MySQLの場合のみ実行
if ($this->connection->getDatabasePlatform()->getName() !== 'mysql') {
return;
}
// カラムを削除
$this->addSql('ALTER TABLE dtb_school DROP COLUMN IF EXISTS display_product_notice');
$this->addSql('ALTER TABLE dtb_school DROP COLUMN IF EXISTS product_notice_text');
}
}