Files
youzan-datahub/sql/migrate_item_price_to_cents.sql

21 lines
926 B
SQL
Raw Permalink 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.
-- ================================================
-- 商品表 price 字段迁移DECIMAL(12,2) → BIGINT
-- 执行前提:已有数据的 price/cost_price 含小数点(如 10.00
-- 执行顺序:先改类型,再清除已入库的错误数据让重新同步
-- ================================================
USE youzandatahub;
-- Step 1: 修改字段类型 DECIMAL → BIGINT
ALTER TABLE `dim_item_sku`
MODIFY COLUMN `price` BIGINT DEFAULT 0 COMMENT '当前售卖价(单位:分)',
MODIFY COLUMN `cost_price` BIGINT DEFAULT 0 COMMENT '成本价(单位:分,若有)';
-- Step 2: 清除已入库的商品数据(因为旧数据的 price 可能被错误解析)
-- 重新同步后会自动用正确的分单位入库
TRUNCATE TABLE `dim_item_sku`;
-- 验证
-- SELECT COUNT(*) FROM dim_item_sku; -- 应为 0
-- 然后调用 GET http://localhost:8080/api/sync/item 重新同步