ALTER TABLE content_categories
  ADD COLUMN IF NOT EXISTS site_name TEXT,
  ADD COLUMN IF NOT EXISTS site_slug TEXT,
  ADD COLUMN IF NOT EXISTS site_enabled BOOLEAN NOT NULL DEFAULT TRUE;

UPDATE content_categories
SET site_name = CASE sort_order
      WHEN 1 THEN 'Одежда'
      WHEN 2 THEN 'Снаряжение'
      WHEN 3 THEN 'Броня'
      WHEN 4 THEN 'Аксессуары'
      WHEN 5 THEN 'Связь'
      WHEN 6 THEN 'Патчи'
      WHEN 7 THEN 'Навигация'
      WHEN 8 THEN 'Прицелы'
      WHEN 9 THEN 'Ночные приборы'
      WHEN 10 THEN 'Медицина'
      WHEN 11 THEN 'Свет'
      WHEN 12 THEN 'Электроника'
      WHEN 13 THEN 'Ножи'
      WHEN 14 THEN 'Оружейный обвес'
      WHEN 15 THEN 'Практика'
      WHEN 16 THEN 'Теория'
      WHEN 17 THEN 'Пушки'
      WHEN 18 THEN 'НЦК'
      ELSE initcap(replace(tag, '_', ' '))
    END,
    site_slug = CASE sort_order
      WHEN 1 THEN 'odezhda'
      WHEN 2 THEN 'snaryazhenie'
      WHEN 3 THEN 'bronya'
      WHEN 4 THEN 'aksessuary'
      WHEN 5 THEN 'svyaz'
      WHEN 6 THEN 'patchi'
      WHEN 7 THEN 'navigatsiya'
      WHEN 8 THEN 'pricely'
      WHEN 9 THEN 'nochnye-pribory'
      WHEN 10 THEN 'medicina'
      WHEN 11 THEN 'svet'
      WHEN 12 THEN 'elektronika'
      WHEN 13 THEN 'nozhi'
      WHEN 14 THEN 'oruzheynyy-obves'
      WHEN 15 THEN 'praktika'
      WHEN 16 THEN 'teoriya'
      WHEN 17 THEN 'pushki'
      WHEN 18 THEN 'nck'
      ELSE site_slug
    END,
    site_enabled = sort_order <> 18,
    updated_at = NOW();

ALTER TABLE content_categories
  ALTER COLUMN site_name SET NOT NULL,
  ALTER COLUMN site_slug SET NOT NULL;

CREATE UNIQUE INDEX IF NOT EXISTS idx_content_categories_site_slug
ON content_categories(site_slug);
