app/DoctrineMigrations/Version20251203000000.php line 1

Open in your IDE?
  1. <?php
    
    declare(strict_types=1);
    
    namespace DoctrineMigrations;
    
    use Doctrine\DBAL\Schema\Schema;
    use Doctrine\Migrations\AbstractMigration;
    
    /**
     * dtb_csvにSchool関連のCSVフィールドを追加するマイグレーション
     */
    final class Version20251203000000 extends AbstractMigration
    {
        const NAME = 'dtb_csv';
    
        public function up(Schema $schema): void
        {
            if (!$schema->hasTable(self::NAME)) {
                return;
            }
    
            // 学校(ID)フィールドの追加
            $schoolIdExists = $this->connection->fetchOne(
                "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)'",
                ['Eccube\\Entity\\Customer']
            );
            
            if ($schoolIdExists == 0) {
                $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')");
            }
    
            // 学校(名称)フィールドの追加
            $schoolNameExists = $this->connection->fetchOne(
                "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 = '学校(名称)'",
                ['Eccube\\Entity\\Customer']
            );
            
            if ($schoolNameExists == 0) {
                $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')");
            }
        }
    
        public function down(Schema $schema): void
        {
            // this down() migration is auto-generated, please modify it to your needs
        }
    }