<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20230618104505 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add region field to countries table';
}
public function up(Schema $schema): void
{
$this->addSql("
ALTER TABLE `country`
ADD COLUMN `region_id` int UNSIGNED NULL AFTER `id`,
ADD INDEX(`region_id`),
ADD CONSTRAINT `country_region_id_ibfk_1` FOREIGN KEY (`region_id`) REFERENCES `region` (`id`);
");
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE `country` DROP FOREIGN KEY `country_region_id_ibfk_1`');
$this->addSql('ALTER TABLE `country` DROP COLUMN `region_id`');
}
}