<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* 学校マスターにセット商品のサイズ(規格)表示フラグを追加
*/
final class Version20251021100000 extends AbstractMigration
{
public function getDescription(): string
{
return 'dtb_schoolテーブルにreport_setproduct_size_flag(smallint)を追加 - セット商品のサイズ表示ON/OFF';
}
public function up(Schema $schema): void
{
$schemaManager = $this->connection->createSchemaManager();
if (!$schemaManager->tablesExist(['dtb_school'])) {
return;
}
$columns = $schemaManager->listTableColumns('dtb_school');
$has = false;
foreach ($columns as $column) {
if ($column->getName() === 'report_setproduct_size_flag') {
$has = true;
break;
}
}
if (!$has) {
// デフォルトは1(表示)
$this->addSql('ALTER TABLE dtb_school ADD report_setproduct_size_flag SMALLINT UNSIGNED NULL DEFAULT 1');
}
}
public function down(Schema $schema): void
{
$schemaManager = $this->connection->createSchemaManager();
if (!$schemaManager->tablesExist(['dtb_school'])) {
return;
}
$columns = $schemaManager->listTableColumns('dtb_school');
$has = false;
foreach ($columns as $column) {
if ($column->getName() === 'report_setproduct_size_flag') {
$has = true;
break;
}
}
if ($has) {
$this->addSql('ALTER TABLE dtb_school DROP report_setproduct_size_flag');
}
}
}