Files
MoneyFlix/crm/Modules/Advertising/Database/Migrations/AddGoogleSheetsFieldsToCampaignsTable.php
T
1sonhador 88a5659fe8 fix: Correct user permissions and UserModel query
- 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
2025-10-15 14:14:00 +01:00

77 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
use App\Core\Database\Migration;
use App\Core\Database\SchemaBuilder;
/**
* Migration: Add Google Sheets integration fields to advertising_campaigns table
*
* This migration adds the necessary fields to integrate Google Sheets data
* with the existing advertising campaigns system, maintaining backward compatibility.
*/
class AddGoogleSheetsFieldsToCampaignsTable extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
// Add Google Sheets integration fields using direct SQL
$sql = "
ALTER TABLE advertising_campaigns
ADD COLUMN script_id VARCHAR(32) NULL UNIQUE COMMENT 'Google Sheets script_id (unique key)',
ADD COLUMN campaign_code VARCHAR(100) NULL COMMENT 'Campaign code from Google Sheets',
ADD COLUMN allowed_geos VARCHAR(255) NULL COMMENT 'Allowed countries/geos (comma separated)',
ADD COLUMN click_mode BOOLEAN DEFAULT FALSE COMMENT 'Click mode enabled',
ADD COLUMN brand VARCHAR(100) NULL COMMENT 'Brand name',
ADD COLUMN campaign_slug VARCHAR(100) NULL UNIQUE COMMENT 'Campaign slug (unique)',
ADD COLUMN allow_close BOOLEAN DEFAULT TRUE COMMENT 'Allow close button',
ADD COLUMN analytics_token VARCHAR(32) NULL COMMENT 'Analytics tracking token',
ADD COLUMN init_after_element_selector VARCHAR(255) NULL COMMENT 'CSS selector for initialization',
ADD COLUMN impressions_target INT NULL COMMENT 'Target impressions',
ADD COLUMN upfront_payment DECIMAL(12,2) NULL COMMENT 'Upfront payment amount',
ADD COLUMN duration_days INT NULL COMMENT 'Campaign duration in days',
ADD COLUMN custom_fields JSON NULL COMMENT 'Custom fields (p,q,r,s,t,u,v,w,x,y,z,INFO,INFO2)',
ADD COLUMN google_sheets_hash VARCHAR(32) NULL COMMENT 'Hash for sync control',
ADD COLUMN last_sync_at TIMESTAMP NULL COMMENT 'Last synchronization timestamp'
";
$this->db->query($sql);
// Add indexes
$this->db->query("ALTER TABLE advertising_campaigns ADD INDEX idx_script_id (script_id)");
$this->db->query("ALTER TABLE advertising_campaigns ADD INDEX idx_campaign_slug (campaign_slug)");
$this->db->query("ALTER TABLE advertising_campaigns ADD INDEX idx_last_sync_at (last_sync_at)");
echo "✅ Added Google Sheets integration fields to advertising_campaigns\n";
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('advertising_campaigns', function (SchemaBuilder $table) {
// Remove Google Sheets integration fields
$table->dropColumn([
'script_id',
'campaign_code',
'allowed_geos',
'click_mode',
'brand',
'campaign_slug',
'allow_close',
'analytics_token',
'init_after_element_selector',
'impressions_target',
'upfront_payment',
'duration_days',
'custom_fields',
'google_sheets_hash',
'last_sync_at'
]);
});
}
}