migrations/Version20260623082329.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. final class Version20260623082329 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Create a position attribute into step table';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql('ALTER TABLE step ADD position INT NOT NULL DEFAULT 0');
  15.         $this->addSql('
  16.             UPDATE step s1
  17.             JOIN (
  18.                 SELECT
  19.                     id,
  20.                     ROW_NUMBER() OVER (
  21.                         PARTITION BY product_id
  22.                         ORDER BY id
  23.                     ) AS position
  24.                 FROM step
  25.             ) s2 ON s2.id = s1.id
  26.             SET s1.position = s2.position
  27.         ');
  28.     }
  29.     public function down(Schema $schema): void
  30.     {
  31.         $this->addSql('ALTER TABLE step DROP position');
  32.     }
  33. }