bindbox-game/migrations/20260129_backfill_product_ids.sql

17 lines
799 B
SQL
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 回填现有订单的产品ID从 raw_data JSON中提取
-- 这个脚本用于更新已存在但 douyin_product_id 为空的订单
-- 方案1从 raw_data JSON 中提取第一个商品的 product_id
UPDATE douyin_orders
SET douyin_product_id = JSON_UNQUOTE(JSON_EXTRACT(raw_data, '$.product_item[0].product_id'))
WHERE douyin_product_id = ''
AND raw_data IS NOT NULL
AND JSON_EXTRACT(raw_data, '$.product_item[0].product_id') IS NOT NULL;
-- 方案2如果 raw_data 使用了不同的 JSON 路径,可以尝试这个
-- UPDATE douyin_orders
-- SET douyin_product_id = JSON_UNQUOTE(JSON_EXTRACT(raw_data, '$.sku_order_list[0].product_id'))
-- WHERE douyin_product_id = ''
-- AND raw_data IS NOT NULL
-- AND JSON_EXTRACT(raw_data, '$.sku_order_list[0].product_id') IS NOT NULL;