Files
myep-team/migrations/Version20260927090000.php
T

50 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Moves destination.country from the raw BusProNet abbreviations to lowercase ISO-2.
*
* The column used to hold whatever BusProNet reported as hotel/land, lowercased: a,
* ch, d, f, i, nl. That set is not a standard - the same country appears as A, AT and
* AUT upstream - so the import now stores the ISO code MyE&P resolves instead, and the
* existing rows are converted to match. The flag icons and the country filters use the
* same vocabulary and are switched with it.
*/
final class Version20260927090000 extends AbstractMigration
{
private const TO_ISO = [
'a' => 'at',
'd' => 'de',
'f' => 'fr',
'i' => 'it',
];
public function getDescription(): string
{
return 'Convert destination.country to lowercase ISO-3166-1 alpha-2';
}
public function up(Schema $schema): void
{
foreach (self::TO_ISO as $legacy => $iso) {
$this->addSql('UPDATE destination SET country = ? WHERE country = ?', [$iso, $legacy]);
}
// ch and nl are already ISO; empty strings were never a country
$this->addSql("UPDATE destination SET country = NULL WHERE country = ''");
}
public function down(Schema $schema): void
{
foreach (self::TO_ISO as $legacy => $iso) {
$this->addSql('UPDATE destination SET country = ? WHERE country = ?', [$legacy, $iso]);
}
}
}