-- 迁移：签收单关联采购单（采购→签收闭环）
-- 时间：2026-06-12
-- 背景：签收时必须指明对应采购单，看板才能追溯"未签收的采购订单"并做超时强调。
-- 执行人：postgres 超级用户（ledger_app 无 DDL 权限）。

ALTER TABLE shipment_signoffs ADD COLUMN IF NOT EXISTS purchase_order_id uuid REFERENCES purchase_orders(id);
GRANT SELECT, INSERT, UPDATE, DELETE ON shipment_signoffs TO ledger_app;
CREATE INDEX IF NOT EXISTS idx_signoffs_purchase_order ON shipment_signoffs(purchase_order_id);

COMMENT ON COLUMN shipment_signoffs.purchase_order_id IS '对应采购/需求单：签收闭环追溯用，新建签收单必填';
