44 lines
1.8 KiB
PHP
44 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DoctrineMigrations;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
/**
|
|
* Copies the library document onto the checklist row.
|
|
*
|
|
* The library holds what the next assignments get and is replaced from season to season, so
|
|
* resolving it on read rewrote what an assignment that already exists - a finished one included -
|
|
* hands out. The row carries its own reference from now on.
|
|
*
|
|
* The backfill maps every existing row to what it resolves to today, so nothing changes for the
|
|
* rows that are already out there. ON DELETE SET NULL keeps a row readable when the library file
|
|
* itself is deleted: "kein Dokument hinterlegt" is a state every view already handles.
|
|
*/
|
|
final class Version20260917140000 extends AbstractMigration
|
|
{
|
|
public function getDescription(): string
|
|
{
|
|
return 'Give each season checklist row its own document reference';
|
|
}
|
|
|
|
public function up(Schema $schema): void
|
|
{
|
|
$this->addSql('ALTER TABLE season_assignment_task ADD document_id INT DEFAULT NULL');
|
|
$this->addSql('ALTER TABLE season_assignment_task ADD CONSTRAINT FK_BEEB9D8DC33F7837 FOREIGN KEY (document_id) REFERENCES upload (id) ON DELETE SET NULL');
|
|
$this->addSql('CREATE INDEX IDX_BEEB9D8DC33F7837 ON season_assignment_task (document_id)');
|
|
|
|
$this->addSql('UPDATE season_assignment_task t JOIN season_task_document d ON d.task_key = t.task_key SET t.document_id = d.document_id');
|
|
}
|
|
|
|
public function down(Schema $schema): void
|
|
{
|
|
$this->addSql('ALTER TABLE season_assignment_task DROP FOREIGN KEY FK_BEEB9D8DC33F7837');
|
|
$this->addSql('DROP INDEX IDX_BEEB9D8DC33F7837 ON season_assignment_task');
|
|
$this->addSql('ALTER TABLE season_assignment_task DROP document_id');
|
|
}
|
|
}
|