Files
myep-team/migrations/Version20260916160000.php

55 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Replaces the season assignment's Destination relation with its own period and house.
*
* A Destination is one travel with one departure window; an all-season placement runs a whole
* season at one house, so the relation only ever meant "borrow three scalars from an arbitrary
* travel row". The house is now a key of the configured "houses" map, which is keyed by the
* normalized hotel code - hence the SER stripping in the backfill, mirroring
* App\Entity\Destination::getHotelCodeNormalized().
*
* Written by hand rather than taken from doctrine:migrations:diff, like Version20260909124625 -
* the diff against this database also carries the pre-existing drift in datetime and JSON column
* declarations, which has nothing to do with this feature.
*/
final class Version20260916160000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Move season assignment period and house onto the assignment itself';
}
public function up(Schema $schema): void
{
// nullable first, so the existing rows can be backfilled before the columns are tightened
$this->addSql('ALTER TABLE season_assignment ADD date_from DATE DEFAULT NULL, ADD date_to DATE DEFAULT NULL, ADD hotel_code VARCHAR(32) DEFAULT NULL');
$this->addSql('UPDATE season_assignment sa JOIN destination d ON d.id = sa.destination_id SET sa.date_from = d.date_from, sa.date_to = d.date_to, sa.hotel_code = CASE WHEN d.hotel_code LIKE \'SER%\' THEN SUBSTRING(d.hotel_code, 4, 3) ELSE SUBSTRING(d.hotel_code, 1, 3) END');
$this->addSql('ALTER TABLE season_assignment CHANGE date_from date_from DATE NOT NULL, CHANGE date_to date_to DATE NOT NULL, CHANGE hotel_code hotel_code VARCHAR(32) NOT NULL');
$this->addSql('ALTER TABLE season_assignment DROP FOREIGN KEY FK_FB891D816C6140');
$this->addSql('DROP INDEX IDX_FB891D816C6140 ON season_assignment');
$this->addSql('ALTER TABLE season_assignment DROP destination_id');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE season_assignment ADD destination_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE season_assignment ADD CONSTRAINT FK_FB891D816C6140 FOREIGN KEY (destination_id) REFERENCES destination (id)');
$this->addSql('CREATE INDEX IDX_FB891D816C6140 ON season_assignment (destination_id)');
// The destination a placement was cut from cannot be recovered from a period and a house
// code, so the relation comes back empty.
$this->addSql('ALTER TABLE season_assignment DROP date_from, DROP date_to, DROP hotel_code');
}
}