Files
myep/migrations/Version20260804140000.php

43 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260804140000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add manual ordering position to additional services';
}
public function up(Schema $schema): void
{
// The default only backfills existing rows; it is dropped again so the column matches the mapping.
$this->addSql('ALTER TABLE additional_service ADD position INT DEFAULT 0 NOT NULL');
$this->addSql('ALTER TABLE additional_service ALTER COLUMN position DROP DEFAULT');
// Seed the positions with the ordering the admin overview used before, so nothing changes
// visually until someone actually drags a row.
$this->addSql('
UPDATE additional_service s
JOIN (
SELECT id, ROW_NUMBER() OVER (
PARTITION BY accommodation_id
ORDER BY date_from ASC, (price <> 0) ASC, label ASC
) AS rn
FROM additional_service
) o ON o.id = s.id
SET s.position = o.rn
');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE additional_service DROP position');
}
}