Files
baiyue-firstleg/scripts/db/test-return-relabel-checks.sql
2026-09-20 18:51:10 +08:00

19 lines
1.0 KiB
SQL

-- Test-only targeted alignment with the authoritative Lastleg initialization checks.
-- Execute only against the explicitly authorized test connection; no row updates.
-- Both old checks must exist. Failure must stop execution, not disable enforcement.
ALTER TABLE baiyue_lastleg.ll_return_inventory_carton
DROP CHECK chk_ll_return_inventory_carton_quantity,
DROP CHECK chk_ll_return_inventory_carton_status,
ADD CONSTRAINT chk_ll_return_inventory_carton_quantity CHECK (
(status IN ('AVAILABLE', 'RELABEL_PENDING', 'OUTBOUNDED') AND sku_types > 0 AND total_quantity > 0)
OR (status = 'MERGED' AND sku_types = 0 AND total_quantity = 0)
),
ADD CONSTRAINT chk_ll_return_inventory_carton_status CHECK (
status IN ('AVAILABLE', 'RELABEL_PENDING', 'MERGED', 'OUTBOUNDED')
);
SELECT CONSTRAINT_NAME, CHECK_CLAUSE
FROM information_schema.CHECK_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = 'baiyue_lastleg'
AND CONSTRAINT_NAME IN ('chk_ll_return_inventory_carton_quantity', 'chk_ll_return_inventory_carton_status');