-- Add gad_source and gad_campaignid columns to call_clicks for Google Ads attribution.
-- Safe to re-run: uses IF NOT EXISTS guard pattern.

SET @db := DATABASE();

SET @sql := IF(
    (SELECT COUNT(*) FROM information_schema.COLUMNS
     WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'call_clicks' AND COLUMN_NAME = 'gad_source') = 0,
    'ALTER TABLE call_clicks ADD COLUMN gad_source VARCHAR(64) NULL AFTER wbraid',
    'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
    (SELECT COUNT(*) FROM information_schema.COLUMNS
     WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'call_clicks' AND COLUMN_NAME = 'gad_campaignid') = 0,
    'ALTER TABLE call_clicks ADD COLUMN gad_campaignid VARCHAR(64) NULL AFTER gad_source',
    'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
