-- 2026-06-05 Campaign media + standalone message logs permissions
ALTER TABLE `campaign`
  ADD COLUMN `media_url` VARCHAR(500) NULL AFTER `email_subject`,
  ADD COLUMN `media_type` VARCHAR(30) NULL AFTER `media_url`;

-- Give existing users access to the new Messages Log page when permissions table exists.
INSERT INTO `user_permissions` (`account_id`, `user_id`, `page_key`, `action_key`, `allowed`, `created_at`)
SELECT DISTINCT up.account_id, up.user_id, 'message_logs', 'view', 1, NOW()
FROM `user_permissions` up
WHERE NOT EXISTS (
  SELECT 1 FROM `user_permissions` x
  WHERE x.account_id=up.account_id AND x.user_id=up.user_id AND x.page_key='message_logs' AND x.action_key='view'
);
