<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* 購入明細書(納品書)のフォントサイズ設定機能を追加するためのマイグレーション
* dtb_schoolテーブルにreport_font_sizeフィールドを追加
*/
final class Version20251020100000 extends AbstractMigration
{
public function getDescription(): string
{
return 'dtb_schoolテーブルにreport_font_size(smallint)を追加 - 購入明細書(納品書)のフォントサイズ設定機能用';
}
public function up(Schema $schema): void
{
// report_font_sizeカラムが存在するかチェック
$schemaManager = $this->connection->createSchemaManager();
// テーブルが存在するかチェック
if (!$schemaManager->tablesExist(['dtb_school'])) {
// テーブルが存在しない場合はスキップ
return;
}
$columns = $schemaManager->listTableColumns('dtb_school');
$hasReportFontSize = false;
foreach ($columns as $column) {
if ($column->getName() === 'report_font_size') {
$hasReportFontSize = true;
break;
}
}
// report_font_sizeカラムが存在しない場合のみ追加
// デフォルト値は2(中サイズ)
if (!$hasReportFontSize) {
$this->addSql('ALTER TABLE dtb_school ADD report_font_size SMALLINT UNSIGNED NULL DEFAULT 2');
}
}
public function down(Schema $schema): void
{
// rollback処理 - カラムが存在する場合のみ削除
$schemaManager = $this->connection->createSchemaManager();
// テーブルが存在するかチェック
if (!$schemaManager->tablesExist(['dtb_school'])) {
return;
}
$columns = $schemaManager->listTableColumns('dtb_school');
$hasReportFontSize = false;
foreach ($columns as $column) {
if ($column->getName() === 'report_font_size') {
$hasReportFontSize = true;
break;
}
}
if ($hasReportFontSize) {
$this->addSql('ALTER TABLE dtb_school DROP report_font_size');
}
}
}