app/DoctrineMigrations/Version20251001224506.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 Version20251001224506 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '関連商品設定テーブルを作成';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // 関連商品設定テーブルを作成
  18.         $this->addSql('CREATE TABLE dtb_related_product_setting (
  19.             id INT AUTO_INCREMENT NOT NULL,
  20.             product_id INT UNSIGNED NOT NULL,
  21.             sort_no INT UNSIGNED NOT NULL,
  22.             create_date DATETIME NOT NULL,
  23.             update_date DATETIME NOT NULL,
  24.             INDEX IDX_RELATED_PRODUCT_PRODUCT_ID (product_id),
  25.             PRIMARY KEY(id)
  26.         ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  27.         // 外部キー制約を追加
  28.         $this->addSql('ALTER TABLE dtb_related_product_setting ADD CONSTRAINT FK_RELATED_PRODUCT_PRODUCT_ID FOREIGN KEY (product_id) REFERENCES dtb_product (id)');
  29.     }
  30.     public function down(Schema $schema): void
  31.     {
  32.         // テーブルを削除
  33.         $this->addSql('DROP TABLE dtb_related_product_setting');
  34.     }
  35. }