<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20251027105034 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create table std_ads_tracking to log both impressions and clicks for advertisements (aligned types)';
}
public function up(Schema $schema): void
{
$this->addSql(<<<'SQL'
CREATE TABLE `std_ads_tracking` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`campaign_id` INT UNSIGNED NOT NULL,
`advertisement_id` INT UNSIGNED NOT NULL,
`zone_id` INT UNSIGNED NOT NULL,
`page` VARCHAR(255) DEFAULT NULL,
`ip` VARCHAR(100) DEFAULT NULL,
`user_id` INT UNSIGNED DEFAULT NULL,
`event_type` ENUM('impression','click') NOT NULL,
`target_href` VARCHAR(512) DEFAULT NULL,
`datetime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_tracking_campaign` (`campaign_id`),
KEY `idx_tracking_advertisement` (`advertisement_id`),
KEY `idx_tracking_zone` (`zone_id`),
CONSTRAINT `fk_tracking_campaign`
FOREIGN KEY (`campaign_id`)
REFERENCES `std_ads_campaigns` (`id`)
ON DELETE CASCADE,
CONSTRAINT `fk_tracking_advertisement`
FOREIGN KEY (`advertisement_id`)
REFERENCES `std_advertisements` (`id`)
ON DELETE CASCADE,
CONSTRAINT `fk_tracking_zone`
FOREIGN KEY (`zone_id`)
REFERENCES `std_ads_zones` (`id`)
ON DELETE CASCADE
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_unicode_ci;
SQL);
}
public function down(Schema $schema): void
{
$this->addSql('DROP TABLE IF EXISTS `std_ads_tracking`');
}
}