ALTER TABLE public.articles
ADD COLUMN IF NOT EXISTS media_gallery jsonb NOT NULL DEFAULT '[]'::jsonb;

ALTER TABLE public.articles
ADD COLUMN IF NOT EXISTS featured_media_id varchar(255);

UPDATE public.articles
SET media_gallery = COALESCE(hero_images, '[]'::jsonb)
WHERE media_gallery = '[]'::jsonb
  AND COALESCE(jsonb_array_length(hero_images), 0) > 0;
