46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DoctrineMigrations;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
/**
|
|
* Numbers the places of an assignment, for the n8n placements feed ("platz_id").
|
|
*
|
|
* Existing active placements are numbered 1..n per assignment in creation order; called-off ones
|
|
* stay without a number, they hold no place. n8n has not seen a place number yet, so the initial
|
|
* order is free to choose.
|
|
*
|
|
* Written by hand rather than taken from doctrine:migrations:diff, which also carries the
|
|
* pre-existing drift of the dev database.
|
|
*/
|
|
final class Version20261106100000 extends AbstractMigration
|
|
{
|
|
public function getDescription(): string
|
|
{
|
|
return 'Add disposition.slot and number the active placements per assignment';
|
|
}
|
|
|
|
public function up(Schema $schema): void
|
|
{
|
|
$this->addSql('ALTER TABLE disposition ADD slot SMALLINT DEFAULT NULL');
|
|
$this->addSql(<<<'SQL'
|
|
UPDATE disposition
|
|
INNER JOIN (
|
|
SELECT id, ROW_NUMBER() OVER (PARTITION BY assignment_id ORDER BY id) AS slot
|
|
FROM disposition
|
|
WHERE status <> 'called_off' AND assignment_id IS NOT NULL
|
|
) AS numbered ON numbered.id = disposition.id
|
|
SET disposition.slot = numbered.slot
|
|
SQL);
|
|
}
|
|
|
|
public function down(Schema $schema): void
|
|
{
|
|
$this->addSql('ALTER TABLE disposition DROP slot');
|
|
}
|
|
}
|