app/DoctrineMigrations/Version20260116134623.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 Version20260116134623 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'Update order status from 99 to 5 and delete order status with id 5';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // Update all orders with status 99 to status 5
  18.         $this->addSql("
  19.             UPDATE dtb_order
  20.             SET order_status_id = 5
  21.             WHERE order_status_id = 99
  22.         ");
  23.         // Delete order status with id 99
  24.         $this->addSql("
  25.             DELETE FROM mtb_order_status
  26.             WHERE id = 99
  27.         ");
  28.     }
  29.     public function down(Schema $schema): void
  30.     {
  31.         // Recreate order status with id 99 (発送済み)
  32.         $this->addSql("
  33.             INSERT INTO mtb_order_status (
  34.                 id,
  35.                 name,
  36.                 display_order_count,
  37.                 sort_no,
  38.                 discriminator_type
  39.             )
  40.             SELECT
  41.                 99,
  42.                 '発送済み',
  43.                 0,
  44.                 1,
  45.                 'orderstatus'
  46.             WHERE NOT EXISTS (
  47.                 SELECT 1 FROM mtb_order_status WHERE id = 99
  48.             )
  49.         ");
  50.         // Revert orders from status 5 back to status 99
  51.         $this->addSql("
  52.             UPDATE dtb_order
  53.             SET order_status_id = 99
  54.             WHERE order_status_id = 5
  55.         ");
  56.     }
  57. }