-- Bilingual portfolio titles (legacy name / name_en)
ALTER TABLE portfolios
  ADD COLUMN IF NOT EXISTS title_fa VARCHAR(255);

ALTER TABLE portfolios
  ADD COLUMN IF NOT EXISTS title_en VARCHAR(255);

-- Existing rows: FA from title; EN from content.nameEn when present
UPDATE portfolios
SET title_fa = title
WHERE title_fa IS NULL;

UPDATE portfolios
SET title_en = NULLIF(BTRIM(content->>'nameEn'), '')
WHERE title_en IS NULL
  AND content ? 'nameEn';

-- Keep title as the primary FA display title
UPDATE portfolios
SET title = COALESCE(NULLIF(BTRIM(title_fa), ''), title)
WHERE title_fa IS NOT NULL;
