diff --git a/backend/migrations/097_fix_migrated_purchase_menu_label_icon.sql b/backend/migrations/097_fix_migrated_purchase_menu_label_icon.sql new file mode 100644 index 0000000000..80c0fd13c8 --- /dev/null +++ b/backend/migrations/097_fix_migrated_purchase_menu_label_icon.sql @@ -0,0 +1,45 @@ +-- 097_fix_migrated_purchase_menu_label_icon.sql +-- +-- Fixes the custom menu item created by migration 096: updates the label +-- from hardcoded English "Purchase" to "充值/订阅", and sets the icon_svg +-- to a credit-card SVG matching the sidebar CreditCardIcon. +-- +-- Idempotent: only modifies items where id = 'migrated_purchase_subscription'. + +DO $$ +DECLARE + v_raw text; + v_items jsonb; + v_idx int; + v_icon text; +BEGIN + SELECT value INTO v_raw + FROM settings WHERE key = 'custom_menu_items'; + + IF COALESCE(v_raw, '') = '' OR v_raw = 'null' THEN + RETURN; + END IF; + + v_items := v_raw::jsonb; + + -- Find the index of the migrated item + SELECT ordinality - 1 INTO v_idx + FROM jsonb_array_elements(v_items) WITH ORDINALITY AS elem + WHERE elem ->> 'id' = 'migrated_purchase_subscription' + LIMIT 1; + + IF v_idx IS NULL THEN + RETURN; -- item not found, nothing to fix + END IF; + + -- Credit card SVG (Heroicons outline, matches CreditCardIcon in AppSidebar) + v_icon := ''; + + -- Update label and icon_svg + v_items := jsonb_set(v_items, ARRAY[v_idx::text, 'label'], '"充值/订阅"'::jsonb); + v_items := jsonb_set(v_items, ARRAY[v_idx::text, 'icon_svg'], to_jsonb(v_icon)); + + UPDATE settings SET value = v_items::text WHERE key = 'custom_menu_items'; + + RAISE NOTICE '[migration-097] Fixed migrated_purchase_subscription: label=充值/订阅, icon=CreditCard SVG'; +END $$;