app/DoctrineMigrations/Version20240326085812.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.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20240326085812 extends AbstractMigration
  10. {
  11.     const csvs = [
  12.         [
  13.             'csv_type_id' => 1,
  14.             'entity_name' => 'Eccube\\\Entity\\\Product',
  15.             'field_name' => 'name_kana',
  16.             'disp_name' => '商品名(かな)',
  17.             'enabled' => true,
  18.         ],
  19.     ];
  20.     public function getDescription(): string
  21.     {
  22.         return '';
  23.     }
  24.     public function up(Schema $schema): void
  25.     {
  26.         foreach (self::csvs as $csv) {
  27.             $referece_field_name $csv['reference_field_name'] ?? null;
  28.             $this->addSql(
  29.                 "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 (
  30.                     {$csv['csv_type_id']},
  31.                     null,
  32.                     '{$csv['entity_name']}',
  33.                     '{$csv['field_name']}',
  34.                     '{$referece_field_name}',
  35.                     '{$csv['disp_name']}',
  36.                     (SELECT c.sort_no FROM dtb_csv as c WHERE c.csv_type_id = {$csv['csv_type_id']} ORDER BY c.sort_no DESC LIMIT 1) + 1,
  37.                     1,
  38.                     NOW(),
  39.                     NOW(),
  40.                     'csv'
  41.                 )"
  42.             );
  43.         }
  44.     }
  45.     public function down(Schema $schema): void
  46.     {
  47.         foreach (self::csvs as $csv) {
  48.             $this->addSql(
  49.                 "DELETE FROM dtb_csv WHERE entity_name = '{$csv['entity_name']}' AND field_name = '{$csv['field_name']}'"
  50.             );
  51.         }
  52.     }
  53. }