app/DoctrineMigrations/Version20250101042651.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 Version20250101042651 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         if ($schema->hasTable("mtb_genre")) {
  19.             return;
  20.         }
  21.         $this->addSql("CREATE TABLE `mtb_genre` (
  22.             `id` smallint unsigned NOT NULL,
  23.             `name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
  24.             `sort_no` smallint unsigned NOT NULL,
  25.             `discriminator_type` varchar(255) COLLATE utf8mb4_bin NOT NULL,
  26.             PRIMARY KEY (`id`)
  27.             ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin");
  28.         // add data table genre
  29.         $this->addSql("
  30.             INSERT INTO `mtb_genre` (`id`,`name`,`sort_no`,`discriminator_type`) VALUES (1,'Blu-ray',1,'genre');
  31.             INSERT INTO `mtb_genre` (`id`,`name`,`sort_no`,`discriminator_type`) VALUES (2,'DVD',2,'genre');
  32.             INSERT INTO `mtb_genre` (`id`,`name`,`sort_no`,`discriminator_type`) VALUES (3,'CD',3,'genre');
  33.             INSERT INTO `mtb_genre` (`id`,`name`,`sort_no`,`discriminator_type`) VALUES (4,'DX BOX',4,'genre');
  34.             INSERT INTO `mtb_genre` (`id`,`name`,`sort_no`,`discriminator_type`) VALUES (5,'Tシャツ付',5,'genre');
  35.             INSERT INTO `mtb_genre` (`id`,`name`,`sort_no`,`discriminator_type`) VALUES (6,'グッズ',6,'genre');
  36.             INSERT INTO `mtb_genre` (`id`,`name`,`sort_no`,`discriminator_type`) VALUES (7,'書籍',7,'genre');
  37.             INSERT INTO `mtb_genre` (`id`,`name`,`sort_no`,`discriminator_type`) VALUES (8,'ワードレコーズ・ダイレクト限定',8,'genre');
  38.             INSERT INTO `mtb_genre` (`id`,`name`,`sort_no`,`discriminator_type`) VALUES (9,'チケット',9,'genre');
  39.             INSERT INTO `mtb_genre` (`id`,`name`,`sort_no`,`discriminator_type`) VALUES (10,'SALE',10,'genre');
  40.             INSERT INTO `mtb_genre` (`id`,`name`,`sort_no`,`discriminator_type`) VALUES (11,'LPセット',11,'genre');
  41.             INSERT INTO `mtb_genre` (`id`,`name`,`sort_no`,`discriminator_type`) VALUES (12,'アパレル',12,'genre');
  42.             ");
  43.         // dtb_product_genre
  44.         $this->addSql("CREATE TABLE `dtb_product_genre` (
  45.             `product_id` int unsigned NOT NULL,
  46.             `genre_id` smallint unsigned NOT NULL,
  47.             `discriminator_type` varchar(255) COLLATE utf8mb4_bin NOT NULL,
  48.             PRIMARY KEY (`product_id`,`genre_id`),
  49.             KEY `IDX_B05778914585766B` (`product_id`),
  50.             KEY `IDX_B057789112479DF8` (`genre_id`),
  51.             CONSTRAINT `FK_B057789112479DF8` FOREIGN KEY (`genre_id`) REFERENCES `mtb_genre` (`id`),
  52.             CONSTRAINT `FK_B05778914585766B` FOREIGN KEY (`product_id`) REFERENCES `dtb_product` (`id`)
  53.             ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;");
  54.     }
  55.     public function down(Schema $schema): void
  56.     {
  57.         // this down() migration is auto-generated, please modify it to your needs
  58.         $this->addSql("DROP TABLE mtb_genre;");
  59.         $this->addSql("DROP TABLE dtb_product_genre;");
  60.     }
  61. }