app/DoctrineMigrations/Version20251127060148.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * アパレル発注メールテンプレートを追加
  8.  */
  9. final class Version20251127060148 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'アパレル発注メールテンプレートをdtb_mail_templateに追加';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // アパレル発注メールテンプレートが既に存在するかチェック
  18.         $exists $this->connection->fetchOne(
  19.             "SELECT COUNT(*) FROM dtb_mail_template WHERE file_name = 'Mail/apparel_order.twig'"
  20.         );
  21.         // 存在しない場合のみ追加
  22.         if (!$exists) {
  23.             $now = new \DateTime();
  24.             $this->addSql(
  25.                 "INSERT INTO dtb_mail_template (name, file_name, mail_subject, creator_id, create_date, update_date, discriminator_type) VALUES (?, ?, ?, ?, ?, ?, ?)",
  26.                 [
  27.                     'アパレル発注メール',
  28.                     'Mail/apparel_order.twig',
  29.                     '発注書のご連絡',
  30.                     null,
  31.                     $now->format('Y-m-d H:i:s'),
  32.                     $now->format('Y-m-d H:i:s'),
  33.                     'mailtemplate'
  34.                 ]
  35.             );
  36.         }
  37.     }
  38.     public function down(Schema $schema): void
  39.     {
  40.         // ダウンマイグレーション: アパレル発注メールテンプレートを削除
  41.         $this->addSql("DELETE FROM dtb_mail_template WHERE file_name = 'Mail/apparel_order.twig'");
  42.     }
  43. }