ALTER TABLE marketing_campaigns
ADD COLUMN scheduled_at DATETIME NULL AFTER recipient_count,
ADD COLUMN template_category VARCHAR(40) NOT NULL DEFAULT 'MARKETING' AFTER template_name;

ALTER TABLE marketing_messages
ADD COLUMN attempt_count INT NOT NULL DEFAULT 0 AFTER wa_status,
ADD COLUMN last_attempt_at DATETIME NULL AFTER attempt_count,
ADD COLUMN last_error TEXT NULL AFTER last_attempt_at;

CREATE INDEX idx_marketing_messages_retry
ON marketing_messages (campaign_id, delivery_status, attempt_count, created_at);
