migrations/Version20230618104505.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. final class Version20230618104505 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Add region field to countries table';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql("
  15.             ALTER TABLE `country`
  16.             ADD COLUMN `region_id` int UNSIGNED NULL AFTER `id`,
  17.             ADD INDEX(`region_id`),
  18.             ADD CONSTRAINT `country_region_id_ibfk_1` FOREIGN KEY (`region_id`) REFERENCES `region` (`id`);
  19.         ");
  20.     }
  21.     public function down(Schema $schema): void
  22.     {
  23.         $this->addSql('ALTER TABLE `country` DROP FOREIGN KEY `country_region_id_ibfk_1`');
  24.         $this->addSql('ALTER TABLE `country` DROP COLUMN `region_id`');
  25.     }
  26. }