diff --git a/migrations/20261070_orders_resupply_unique.sql b/migrations/20261070_orders_resupply_unique.sql new file mode 100644 index 0000000..a5305f3 --- /dev/null +++ b/migrations/20261070_orders_resupply_unique.sql @@ -0,0 +1,6 @@ +-- 同一原单只允许存在一张「未完结」的补送单(从根上防重复建补送单) +CREATE UNIQUE INDEX IF NOT EXISTS uq_orders_resupply_per_original + ON orders (branch_code, linked_order_code) + WHERE source = 'return_resupply' + AND linked_order_code IS NOT NULL + AND order_status < 90;