app/DoctrineMigrations/Version20251203000000.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.  * dtb_csvにSchool関連のCSVフィールドを追加するマイグレーション
  8.  */
  9. final class Version20251203000000 extends AbstractMigration
  10. {
  11.     const NAME 'dtb_csv';
  12.     public function up(Schema $schema): void
  13.     {
  14.         if (!$schema->hasTable(self::NAME)) {
  15.             return;
  16.         }
  17.         // 学校(ID)フィールドの追加
  18.         $schoolIdExists $this->connection->fetchOne(
  19.             "SELECT COUNT(*) FROM dtb_csv WHERE csv_type_id = 2 AND entity_name = ? AND field_name = 'School' AND reference_field_name = 'school_id' AND disp_name = '学校(ID)'",
  20.             ['Eccube\\Entity\\Customer']
  21.         );
  22.         
  23.         if ($schoolIdExists == 0) {
  24.             $this->addSql("INSERT INTO dtb_csv (csv_type_id, creator_id, entity_name, field_name, reference_field_name, disp_name, sort_no, enabled, create_date, update_date, discriminator_type) VALUES (2, 1, 'Eccube\\Entity\\Customer', 'School', 'school_id', '学校(ID)', 34, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'csv')");
  25.         }
  26.         // 学校(名称)フィールドの追加
  27.         $schoolNameExists $this->connection->fetchOne(
  28.             "SELECT COUNT(*) FROM dtb_csv WHERE csv_type_id = 2 AND entity_name = ? AND field_name = 'School' AND reference_field_name = 'school_name' AND disp_name = '学校(名称)'",
  29.             ['Eccube\\Entity\\Customer']
  30.         );
  31.         
  32.         if ($schoolNameExists == 0) {
  33.             $this->addSql("INSERT INTO dtb_csv (csv_type_id, creator_id, entity_name, field_name, reference_field_name, disp_name, sort_no, enabled, create_date, update_date, discriminator_type) VALUES (2, 1, 'Eccube\\Entity\\Customer', 'School', 'school_name', '学校(名称)', 35, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'csv')");
  34.         }
  35.     }
  36.     public function down(Schema $schema): void
  37.     {
  38.         // this down() migration is auto-generated, please modify it to your needs
  39.     }
  40. }