-- 발주에 '발주담당'(담당자 manager.mg_idx) 저장 컬럼 추가
-- bo_orderer_idx(발주 작성자 mb_idx) 다음에 bo_manager_idx(발주담당 mg_idx)를 둔다.
-- 실행: mysql -u jongryangje -p jongryangje_dev < writable/database/bag_order_add_manager.sql
-- 멱등 실행(이미 있으면 건너뜀).

SET @db = DATABASE();

SET @sql = IF(
  (SELECT COUNT(*) FROM information_schema.COLUMNS
     WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'bag_order' AND COLUMN_NAME = 'bo_manager_idx') > 0,
  'SELECT ''bo_manager_idx already exists'' AS msg',
  'ALTER TABLE `bag_order` ADD COLUMN `bo_manager_idx` INT UNSIGNED NULL COMMENT ''발주담당 manager.mg_idx'' AFTER `bo_orderer_idx`'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
