-- Category names/descriptions: zh (Simplified), en, ja, ko, vi, id, ms.

ALTER TABLE categories ADD COLUMN IF NOT EXISTS name_zh TEXT;
ALTER TABLE categories ADD COLUMN IF NOT EXISTS name_en TEXT;
ALTER TABLE categories ADD COLUMN IF NOT EXISTS name_ja TEXT;
ALTER TABLE categories ADD COLUMN IF NOT EXISTS name_ko TEXT;
ALTER TABLE categories ADD COLUMN IF NOT EXISTS name_vi TEXT;
ALTER TABLE categories ADD COLUMN IF NOT EXISTS name_id TEXT;
ALTER TABLE categories ADD COLUMN IF NOT EXISTS name_ms TEXT;
ALTER TABLE categories ADD COLUMN IF NOT EXISTS description_zh TEXT;
ALTER TABLE categories ADD COLUMN IF NOT EXISTS description_en TEXT;
ALTER TABLE categories ADD COLUMN IF NOT EXISTS description_ja TEXT;
ALTER TABLE categories ADD COLUMN IF NOT EXISTS description_ko TEXT;
ALTER TABLE categories ADD COLUMN IF NOT EXISTS description_vi TEXT;
ALTER TABLE categories ADD COLUMN IF NOT EXISTS description_id TEXT;
ALTER TABLE categories ADD COLUMN IF NOT EXISTS description_ms TEXT;

UPDATE categories SET name_zh = COALESCE(NULLIF(name_zh, ''), NULLIF(name_zh_cn, ''), name_zh_tw)
  WHERE COALESCE(name_zh, '') = '';
UPDATE categories SET description_zh = COALESCE(description_zh, description_zh_tw)
  WHERE description_zh IS NULL;
