- 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
76 lines
3.8 KiB
PHP
76 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Advertising\Database\Migrations;
|
|
|
|
use App\Core\Database\Migration;
|
|
|
|
class CreateSiteDomainsTable extends Migration
|
|
{
|
|
public function up(): void
|
|
{
|
|
$sql = "
|
|
CREATE TABLE IF NOT EXISTS advertising_site_domains (
|
|
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
cuid VARCHAR(32) NOT NULL UNIQUE COMMENT 'CUID identifier',
|
|
site_group_id BIGINT(20) UNSIGNED NOT NULL COMMENT 'Foreign key to advertising_site_groups',
|
|
domain VARCHAR(255) NOT NULL UNIQUE COMMENT 'Domain name (e.g., example.com)',
|
|
subdomain VARCHAR(255) NULL COMMENT 'Subdomain if applicable',
|
|
status TINYINT(4) NOT NULL DEFAULT 1 COMMENT '1=active, 0=inactive, -1=deleted',
|
|
is_primary TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Is this the primary domain for the site group',
|
|
is_verified TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Has domain ownership been verified',
|
|
ssl_certificate VARCHAR(500) NULL COMMENT 'SSL certificate info',
|
|
ssl_expiry DATE NULL COMMENT 'SSL certificate expiry date',
|
|
dns_settings JSON NULL COMMENT 'DNS configuration settings',
|
|
redirect_rules JSON NULL COMMENT 'Domain redirect rules',
|
|
traffic_weight INT(11) NOT NULL DEFAULT 100 COMMENT 'Traffic distribution weight (0-100)',
|
|
last_checked_at TIMESTAMP NULL COMMENT 'Last domain health check',
|
|
created_by BIGINT(20) UNSIGNED NOT NULL COMMENT 'User who added this domain',
|
|
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 for performance
|
|
INDEX idx_site_group_id (site_group_id),
|
|
INDEX idx_domain (domain),
|
|
INDEX idx_status (status),
|
|
INDEX idx_is_primary (is_primary),
|
|
INDEX idx_created_by (created_by),
|
|
INDEX idx_deleted_at (deleted_at),
|
|
INDEX idx_site_group_status (site_group_id, status),
|
|
INDEX idx_domain_status (domain, status)
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
COMMENT='Domains associated with site groups for campaign targeting'
|
|
";
|
|
|
|
$this->db->query($sql);
|
|
echo "✅ Created advertising_site_domains table\n";
|
|
|
|
// Adicionar foreign key constraints separadamente para melhor controle de erros
|
|
try {
|
|
$this->db->query("ALTER TABLE advertising_site_domains
|
|
ADD CONSTRAINT fk_site_domains_site_group
|
|
FOREIGN KEY (site_group_id) REFERENCES advertising_site_groups(id)
|
|
ON DELETE CASCADE ON UPDATE CASCADE");
|
|
echo "✅ Added foreign key constraint to site_groups\n";
|
|
} catch (\Exception $e) {
|
|
echo "⚠️ Foreign key constraint to site_groups skipped: " . $e->getMessage() . "\n";
|
|
}
|
|
|
|
try {
|
|
$this->db->query("ALTER TABLE advertising_site_domains
|
|
ADD CONSTRAINT fk_site_domains_user
|
|
FOREIGN KEY (created_by) REFERENCES users(id)
|
|
ON DELETE CASCADE ON UPDATE CASCADE");
|
|
echo "✅ Added foreign key constraint to users\n";
|
|
} catch (\Exception $e) {
|
|
echo "⚠️ Foreign key constraint to users skipped: " . $e->getMessage() . "\n";
|
|
}
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
$this->db->query("DROP TABLE IF EXISTS advertising_site_domains");
|
|
echo "✅ Dropped advertising_site_domains table\n";
|
|
}
|
|
} |