<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260623082329 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create a position attribute into step table';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE step ADD position INT NOT NULL DEFAULT 0');
$this->addSql('
UPDATE step s1
JOIN (
SELECT
id,
ROW_NUMBER() OVER (
PARTITION BY product_id
ORDER BY id
) AS position
FROM step
) s2 ON s2.id = s1.id
SET s1.position = s2.position
');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE step DROP position');
}
}