migrations/Version20230611124626.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 Version20230611124626 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Regions table';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql("
  15.             CREATE TABLE `region` (
  16.             `id` int UNSIGNED NOT NULL AUTO_INCREMENT,
  17.             `parent_id` int UNSIGNED NULL,
  18.             `name` varchar(255) NOT NULL,
  19.             PRIMARY KEY (`id`) )
  20.         ");
  21.         $this->addSql("
  22.             ALTER TABLE `region`
  23.             ADD CONSTRAINT `parent_id` FOREIGN KEY (`parent_id`) REFERENCES `region` (`id`)
  24.         ");
  25.     }
  26.     public function down(Schema $schema): void
  27.     {
  28.         $this->addSql("DROP TABLE IF EXISTS `region`");
  29.     }
  30. }