-- 出库流通管理：销售出库与袋码/托盘码关联（无租户字段）
-- 执行前请确认目标数据库为 mom-thzy，并逐条执行。

ALTER TABLE mes_wm_product_sales_detail
  ADD COLUMN bag_code_id bigint DEFAULT NULL COMMENT '袋码编号' AFTER area_id;
ALTER TABLE mes_wm_product_sales_detail
  ADD COLUMN pallet_code_id bigint DEFAULT NULL COMMENT '托盘码编号' AFTER bag_code_id;
ALTER TABLE mes_wm_product_sales_detail
  ADD INDEX idx_sales_detail_bag_code (bag_code_id);
ALTER TABLE mes_wm_product_sales_detail
  ADD INDEX idx_sales_detail_pallet_code (pallet_code_id);

ALTER TABLE mes_pro_bag_code
  ADD COLUMN sales_id bigint DEFAULT NULL COMMENT '最近销售出库单编号' AFTER inbound_line_code;
ALTER TABLE mes_pro_bag_code
  ADD COLUMN outbound_time datetime DEFAULT NULL COMMENT '最近销售出库时间' AFTER sales_id;
ALTER TABLE mes_pro_bag_code
  ADD INDEX idx_bag_code_sales (sales_id);

ALTER TABLE mes_pro_pallet
  ADD COLUMN sales_id bigint DEFAULT NULL COMMENT '最近销售出库单编号' AFTER status;
ALTER TABLE mes_pro_pallet
  ADD COLUMN outbound_time datetime DEFAULT NULL COMMENT '最近销售出库时间' AFTER sales_id;
ALTER TABLE mes_pro_pallet
  ADD INDEX idx_pallet_sales (sales_id);
