-- asr_bas_station 增加出库任务上限配置
-- 用途：按最终出库站限制堆垛机可同时放行的在途出库任务数
-- 适用数据库：MySQL

SET @current_db := DATABASE();

SET @out_task_limit_exists := (
  SELECT COUNT(1)
  FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = @current_db
    AND TABLE_NAME = 'asr_bas_station'
    AND COLUMN_NAME = 'out_task_limit'
);

SET @add_out_task_limit_sql := IF(
  @out_task_limit_exists = 0,
  'ALTER TABLE asr_bas_station ADD COLUMN out_task_limit INT NULL COMMENT ''出库任务上限，<0或NULL表示不限制，0表示禁止新出库'' AFTER station_alias',
  'SELECT ''column out_task_limit already exists'' '
);
PREPARE stmt_out_task_limit FROM @add_out_task_limit_sql;
EXECUTE stmt_out_task_limit;
DEALLOCATE PREPARE stmt_out_task_limit;

SHOW COLUMNS FROM asr_bas_station LIKE 'out_task_limit';
