iloom-flatten/migrations/20260523_163000_sync_company_id_data.sql

28 lines
889 B
SQL
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.

-- ============================================
-- 此文件由 Meoo Cloud 自动生成,请勿修改
-- This file is auto-generated by Meoo Cloud, DO NOT MODIFY
-- ============================================
-- 更新 inventory_records 的 company_id通过 warehouse 关联)
UPDATE public.inventory_records ir
SET company_id = w.company_id
FROM public.warehouses w
WHERE ir.warehouse_id = w.id
AND ir.company_id IS NULL;
-- 更新 yarn_ratios 的 company_id通过 production_plans 关联)
UPDATE public.yarn_ratios yr
SET company_id = pp.purchaser_id
FROM public.production_plans pp
WHERE yr.plan_id = pp.id
AND yr.company_id IS NULL;
-- 更新 plan_process_steps 的 company_id通过 production_plans 关联)
UPDATE public.plan_process_steps pps
SET company_id = pp.purchaser_id
FROM public.production_plans pp
WHERE pps.plan_id = pp.id
AND pps.company_id IS NULL;