- T1 资金/库存/报价/自采 P1(BIZ-1/2/3/4/10/13/14) - T2 主系统反向事件墓碑/改派/孤儿处理(BIZ-6/8/9) - T3 选分公司 ticket、trust proxy、角色权限收口(SEC-2/3/4) - T4 缺列/RLS/tenant 名单/FK/迁移执行器(DATA-1..8) - T5 401 登出/分页/映射口径/blob/ZIP 中文名(FE-1..4/BIZ-15) - T6 测试脚本目标守卫/config fail-fast/容器配置(OPS-2..8) - T7 前后端测试与 lint 门禁清零 - T8 应付卡片按关联订单日(口径 A) - T9 存储对象全链路归属校验、敏感列禁写、审计 target_id 超长修复
92 lines
3.2 KiB
SQL
92 lines
3.2 KiB
SQL
-- 仓内加工需求单:按分公司+配送日+成品SKU汇总;明细挂订单行;领料另表
|
|
-- 见 docs/design/20260823-warehouse-processing-demand-sheet.md
|
|
|
|
DO $$
|
|
DECLARE
|
|
sch text;
|
|
BEGIN
|
|
FOR sch IN
|
|
SELECT nspname
|
|
FROM pg_namespace
|
|
WHERE nspname IN ('public', 'legacy_public', 'tenant_template')
|
|
OR nspname LIKE 'tenant_%'
|
|
ORDER BY CASE nspname
|
|
WHEN 'public' THEN 0
|
|
WHEN 'legacy_public' THEN 1
|
|
WHEN 'tenant_template' THEN 2
|
|
ELSE 3
|
|
END, nspname
|
|
LOOP
|
|
IF to_regclass(format('%I.processing_tasks', sch)) IS NOT NULL THEN
|
|
EXECUTE format(
|
|
'ALTER TABLE %I.processing_tasks ADD COLUMN IF NOT EXISTS demand_delivery_date DATE',
|
|
sch
|
|
);
|
|
EXECUTE format(
|
|
'COMMENT ON COLUMN %I.processing_tasks.demand_delivery_date IS %L',
|
|
sch,
|
|
'需求单配送日;source_type=demand 时与 branch_code+sku_code 组成汇单键'
|
|
);
|
|
EXECUTE format(
|
|
'CREATE UNIQUE INDEX IF NOT EXISTS idx_processing_demand_sheet_key
|
|
ON %I.processing_tasks (branch_code, demand_delivery_date, sku_code)
|
|
WHERE source_type = ''demand'' AND process_status < 50 AND demand_delivery_date IS NOT NULL',
|
|
sch
|
|
);
|
|
END IF;
|
|
|
|
IF to_regclass(format('%I.processing_demand_items', sch)) IS NULL
|
|
AND to_regclass(format('%I.processing_tasks', sch)) IS NOT NULL THEN
|
|
EXECUTE format(
|
|
'CREATE TABLE IF NOT EXISTS %I.processing_demand_items (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
task_id UUID NOT NULL REFERENCES %I.processing_tasks(id) ON DELETE CASCADE,
|
|
order_item_id UUID NOT NULL,
|
|
order_code VARCHAR(50) NOT NULL,
|
|
sku_code VARCHAR(50) NOT NULL,
|
|
qty NUMERIC(12,3) NOT NULL DEFAULT 0,
|
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
|
UNIQUE (order_item_id)
|
|
)',
|
|
sch, sch
|
|
);
|
|
EXECUTE format(
|
|
'CREATE INDEX IF NOT EXISTS idx_processing_demand_items_task ON %I.processing_demand_items (task_id)',
|
|
sch
|
|
);
|
|
EXECUTE format(
|
|
'CREATE INDEX IF NOT EXISTS idx_processing_demand_items_order ON %I.processing_demand_items (order_code)',
|
|
sch
|
|
);
|
|
END IF;
|
|
|
|
IF to_regclass(format('%I.processing_demand_picks', sch)) IS NULL
|
|
AND to_regclass(format('%I.processing_tasks', sch)) IS NOT NULL THEN
|
|
EXECUTE format(
|
|
'CREATE TABLE IF NOT EXISTS %I.processing_demand_picks (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
task_id UUID NOT NULL REFERENCES %I.processing_tasks(id) ON DELETE CASCADE,
|
|
sku_code VARCHAR(50) NOT NULL,
|
|
qty NUMERIC(12,3) NOT NULL DEFAULT 0,
|
|
net_weight NUMERIC(12,3),
|
|
loss_qty NUMERIC(12,3),
|
|
process_unit_price NUMERIC(12,2),
|
|
material_cost NUMERIC(12,2) NOT NULL DEFAULT 0,
|
|
operator_id UUID,
|
|
remark TEXT,
|
|
created_at TIMESTAMPTZ DEFAULT NOW()
|
|
)',
|
|
sch, sch
|
|
);
|
|
EXECUTE format(
|
|
'CREATE INDEX IF NOT EXISTS idx_processing_demand_picks_task ON %I.processing_demand_picks (task_id)',
|
|
sch
|
|
);
|
|
END IF;
|
|
END LOOP;
|
|
END;
|
|
$$;
|
|
|
|
SELECT public.ensure_tenant_schemas_match_template();
|