- Fix storage permissions to use 'www' user instead of 'www-data' - Fix UserModel getAllForAdmin query to avoid placeholders in LIMIT/OFFSET - Import missing modules: Advertising, Dashboard, Analytics - Update deploy script to copy files to public directory
67 lines
3.4 KiB
PHP
67 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Core\Database\Migration;
|
|
|
|
/**
|
|
* Migration: Create Campaign Domains Table
|
|
*
|
|
* Creates advertising_campaign_domains table for optional campaign-specific domains.
|
|
* This allows campaigns to target specific domains within their site group.
|
|
*/
|
|
class CreateCampaignDomainsTable extends Migration
|
|
{
|
|
public function up(): void
|
|
{
|
|
// Create table without foreign keys first
|
|
$sql = "
|
|
CREATE TABLE IF NOT EXISTS advertising_campaign_domains (
|
|
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
cuid VARCHAR(64) NOT NULL UNIQUE COMMENT 'CUID2 identifier',
|
|
campaign_id BIGINT UNSIGNED NOT NULL COMMENT 'Foreign key to advertising_campaigns',
|
|
site_domain_id BIGINT NOT NULL COMMENT 'Foreign key to advertising_site_domains',
|
|
status TINYINT(4) NOT NULL DEFAULT 1 COMMENT '1=active, 0=inactive, -1=deleted',
|
|
targeting_settings JSON NULL COMMENT 'Domain-specific targeting settings',
|
|
created_by BIGINT UNSIGNED NOT NULL COMMENT 'User who created this association',
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
deleted_at TIMESTAMP NULL COMMENT 'Soft delete timestamp',
|
|
|
|
-- Indexes
|
|
INDEX idx_campaign_id (campaign_id),
|
|
INDEX idx_site_domain_id (site_domain_id),
|
|
INDEX idx_status (status),
|
|
INDEX idx_created_by (created_by),
|
|
INDEX idx_deleted_at (deleted_at),
|
|
INDEX idx_campaign_status (campaign_id, status),
|
|
INDEX idx_domain_status (site_domain_id, status),
|
|
|
|
-- Unique constraint to prevent duplicate campaign-domain associations
|
|
UNIQUE KEY unique_campaign_domain (campaign_id, site_domain_id)
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
COMMENT='Optional campaign-specific domains for granular targeting within site groups'
|
|
";
|
|
|
|
$this->db->query($sql);
|
|
|
|
// Add foreign key constraints separately (sometimes this helps with constraint issues)
|
|
try {
|
|
$this->db->query("ALTER TABLE advertising_campaign_domains ADD CONSTRAINT fk_campaign_domains_campaign FOREIGN KEY (campaign_id) REFERENCES advertising_campaigns(id) ON DELETE CASCADE ON UPDATE CASCADE");
|
|
$this->db->query("ALTER TABLE advertising_campaign_domains ADD CONSTRAINT fk_campaign_domains_domain FOREIGN KEY (site_domain_id) REFERENCES advertising_site_domains(id) ON DELETE CASCADE ON UPDATE CASCADE");
|
|
$this->db->query("ALTER TABLE advertising_campaign_domains ADD CONSTRAINT fk_campaign_domains_user FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE");
|
|
} catch (\Exception $e) {
|
|
echo "⚠️ Warning: Could not add foreign key constraints: " . $e->getMessage() . "\n";
|
|
echo " Table created successfully but without foreign key constraints.\n";
|
|
}
|
|
|
|
echo "✅ Created advertising_campaign_domains table\n";
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
$this->db->query("DROP TABLE IF EXISTS advertising_campaign_domains");
|
|
echo "✅ Dropped advertising_campaign_domains table\n";
|
|
}
|
|
} |