CREATE TABLE IF NOT EXISTS `campaign_alerts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `client_id` int(11) NOT NULL,
  `campaign_id` int(11) DEFAULT NULL,
  `campaign_external_id` bigint(20) DEFAULT NULL,
  `ad_group_id` int(11) DEFAULT NULL,
  `ad_group_external_id` bigint(20) DEFAULT NULL,
  `alert_type` varchar(120) NOT NULL,
  `message` text NOT NULL,
  `meta_json` text DEFAULT NULL,
  `date_detected` date NOT NULL,
  `date_add` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_alert_daily` (`client_id`,`campaign_external_id`,`ad_group_external_id`,`alert_type`,`date_detected`),
  KEY `idx_alert_date` (`date_detected`),
  KEY `idx_alert_client` (`client_id`),
  KEY `idx_alert_campaign` (`campaign_id`),
  KEY `idx_alert_ad_group` (`ad_group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
