-- Add a disabled-by-configuration homepage advertising widget to published layouts.
-- The widget itself is harmless until Advertising is enabled in Administration.
INSERT INTO widgets (layout_section_id,type,title,config_json,sort_order,is_enabled,created_at,updated_at)
SELECT ls.id,'ad_slot',NULL,'{"placement":"homepage"}',190,1,NOW(),NOW()
FROM layout_sections ls INNER JOIN layouts l ON l.id=ls.layout_id
WHERE l.status='published' AND ls.section_key='homepage_main'
  AND NOT EXISTS (
      SELECT 1 FROM widgets w
      WHERE w.layout_section_id=ls.id AND w.type='ad_slot'
  );
