migrations/Version20251027105025.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 Version20251027105025 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Create table std_ads_targeting_pages for page-level targeting (many-to-many with rules)';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql(<<<'SQL'
  15.             CREATE TABLE `std_ads_targeting_pages` (
  16.               `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  17.               `rule_id` INT UNSIGNED NOT NULL,
  18.               `page_id` INT UNSIGNED NOT NULL,
  19.               PRIMARY KEY (`id`),
  20.               KEY `idx_targeting_pages_rule` (`rule_id`),
  21.               KEY `idx_targeting_pages_page` (`page_id`),
  22.               CONSTRAINT `fk_targeting_pages_rule`
  23.                 FOREIGN KEY (`rule_id`)
  24.                 REFERENCES `std_ads_targeting_rules` (`id`)
  25.                 ON DELETE CASCADE,
  26.               CONSTRAINT `fk_targeting_pages_page`
  27.                 FOREIGN KEY (`page_id`)
  28.                 REFERENCES `std_pages` (`id`)
  29.                 ON DELETE CASCADE
  30.             )
  31.             ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  32.         SQL);
  33.     }
  34.     public function down(Schema $schema): void
  35.     {
  36.         $this->addSql('DROP TABLE IF EXISTS `std_ads_targeting_pages`');
  37.     }
  38. }