099_fix_migrated_purchase_menu_label_icon.sql 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. -- 097_fix_migrated_purchase_menu_label_icon.sql
  2. --
  3. -- Fixes the custom menu item created by migration 096: updates the label
  4. -- from hardcoded English "Purchase" to "充值/订阅", and sets the icon_svg
  5. -- to a credit-card SVG matching the sidebar CreditCardIcon.
  6. --
  7. -- Idempotent: only modifies items where id = 'migrated_purchase_subscription'.
  8. DO $$
  9. DECLARE
  10. v_raw text;
  11. v_items jsonb;
  12. v_idx int;
  13. v_icon text;
  14. v_elem jsonb;
  15. v_i int := 0;
  16. BEGIN
  17. SELECT value INTO v_raw
  18. FROM settings WHERE key = 'custom_menu_items';
  19. IF COALESCE(v_raw, '') = '' OR v_raw = 'null' THEN
  20. RETURN;
  21. END IF;
  22. v_items := v_raw::jsonb;
  23. -- Find the index of the migrated item by iterating the array
  24. v_idx := NULL;
  25. FOR v_elem IN SELECT jsonb_array_elements(v_items) LOOP
  26. IF v_elem ->> 'id' = 'migrated_purchase_subscription' THEN
  27. v_idx := v_i;
  28. EXIT;
  29. END IF;
  30. v_i := v_i + 1;
  31. END LOOP;
  32. IF v_idx IS NULL THEN
  33. RETURN; -- item not found, nothing to fix
  34. END IF;
  35. -- Credit card SVG (Heroicons outline, matches CreditCardIcon in AppSidebar)
  36. v_icon := '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M2.25 8.25h19.5M2.25 9h19.5m-16.5 5.25h6m-6 2.25h3m-3.75 3h15a2.25 2.25 0 002.25-2.25V6.75A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25v10.5A2.25 2.25 0 004.5 19.5z"/></svg>';
  37. -- Update label and icon_svg
  38. v_items := jsonb_set(v_items, ARRAY[v_idx::text, 'label'], '"充值/订阅"'::jsonb);
  39. v_items := jsonb_set(v_items, ARRAY[v_idx::text, 'icon_svg'], to_jsonb(v_icon));
  40. UPDATE settings SET value = v_items::text WHERE key = 'custom_menu_items';
  41. RAISE NOTICE '[migration-097] Fixed migrated_purchase_subscription: label=充值/订阅, icon=CreditCard SVG';
  42. END $$;