Files
FT546MWS/scripts/shadow-lane-lock/assertions.sql

23 lines
2.1 KiB
Transact-SQL

IF NOT EXISTS(SELECT 1 FROM alg.lane_state WHERE warehouse_id='01' AND lane_code='UNLOCK_N' AND available_count=1)
THROW 51950,'locked=N must be available in the actual lane aggregate',1;
IF (SELECT COUNT(*) FROM alg.lane_state WHERE warehouse_id='01' AND lane_code LIKE 'UNLOCK_%' AND available_count=1 AND pending_outbound=0 AND has_gap=0 AND snapshot_generation=101)<>7
THROW 51950,'NULL, blank, 0, N, trimmed N, released reservation and old generation must remain eligible',1;
IF EXISTS(SELECT 1 FROM alg.lane_state WHERE warehouse_id='01' AND lane_code NOT LIKE 'UNLOCK_%' AND available_count<>0)
THROW 51950,'locked/unknown/occupied/tray/stock/role/reservation/outbound/gap exclusions must remain',1;
IF NOT EXISTS(SELECT 1 FROM alg.lane_state WHERE warehouse_id='01' AND lane_code='OUTBOUND' AND pending_outbound=1 AND available_count=0)
THROW 51950,'outbound must exclude the entire lane',1;
IF NOT EXISTS(SELECT 1 FROM alg.lane_state WHERE warehouse_id='01' AND lane_code='GAP' AND has_gap=1 AND available_count=0)
THROW 51950,'gap must exclude the entire lane',1;
IF NOT EXISTS(SELECT 1 FROM alg.lane_state WHERE warehouse_id='01' AND lane_code='UNLOCK_N' AND space_count=1 AND occupied_count=0)
THROW 51950,'old generation must not pollute current counts',1;
DECLARE @stamp datetime2=(SELECT rebuilt_at FROM alg.lane_state WHERE warehouse_id='01' AND lane_code='UNLOCK_N');
EXEC alg.usp_rebuild_lane_state @warehouse_id='01';
IF (SELECT rebuilt_at FROM alg.lane_state WHERE warehouse_id='01' AND lane_code='UNLOCK_N')<>@stamp
THROW 51950,'unchanged repeat rebuild should not rewrite lane state',1;
EXEC alg.usp_rebuild_lane_state @warehouse_id='02';
EXEC alg.usp_rebuild_lane_state @warehouse_id='01',@lane_code='UNLOCK_N';
IF NOT EXISTS(SELECT 1 FROM alg.lane_state WHERE warehouse_id='02' AND lane_code='OTHER_WAREHOUSE' AND available_count=1 AND snapshot_generation=201)
THROW 51950,'scoped rebuild must preserve other warehouse',1;
IF (SELECT COUNT(*) FROM alg.lane_state WHERE warehouse_id='01')<>16
THROW 51950,'scoped rebuild must preserve other lanes',1;