migrations/Version20250521122553.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 Version20250521122553 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Create std_pages_tags table eelations';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql('CREATE TABLE std_pages_tags (
  15.             id INT AUTO_INCREMENT NOT NULL,
  16.             page_id INT UNSIGNED NOT NULL COMMENT \'Page unique identifier\',
  17.             domain_value_id INT NOT NULL,
  18.             INDEX IDX_3A16310EC4663E4 (page_id),
  19.             INDEX IDX_3A16310EEAAEF4ED (domain_value_id),
  20.             PRIMARY KEY(id)
  21.         ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  22.         $this->addSql('ALTER TABLE std_pages_tags 
  23.             ADD CONSTRAINT FK_3A16310EC4663E4 FOREIGN KEY (page_id) REFERENCES std_pages (id)');
  24.         $this->addSql('ALTER TABLE std_pages_tags 
  25.             ADD CONSTRAINT FK_3A16310EEAAEF4ED FOREIGN KEY (domain_value_id) REFERENCES std_domains_values (id)');
  26.         $this->addSql("
  27.             INSERT INTO std_domains (
  28.                 updated_by,
  29.                 language_code,
  30.                 created_by,
  31.                 machine_name,
  32.                 description,
  33.                 created_date,
  34.                 updated_date
  35.             )
  36.             SELECT 1, 'pt', 1, 'tags', 'Tags', NOW(), NOW()
  37.             FROM dual
  38.             WHERE EXISTS (SELECT 1 FROM std_users WHERE id = 1);
  39.         ");
  40.         $this->addSql("SET @id_domain = LAST_INSERT_ID();");
  41.         $this->addSql("
  42.             UPDATE std_domains 
  43.             SET parent_domain_id = @id_domain 
  44.             WHERE id = @id_domain;
  45.         ");
  46.     }
  47.     public function down(Schema $schema): void
  48.     {
  49.         $this->addSql('ALTER TABLE std_pages_tags DROP FOREIGN KEY FK_3A16310EC4663E4');
  50.         $this->addSql('ALTER TABLE std_pages_tags DROP FOREIGN KEY FK_3A16310EEAAEF4ED');
  51.         $this->addSql('DROP TABLE std_pages_tags');
  52.         $this->addSql("DELETE FROM std_domains WHERE machine_name = 'tags'");
  53.     }
  54. }