/**
 * TBM 작업자 이동 로그 테이블 생성
 * - 작업자를 다른 TBM 세션으로 보내기/빼오기 기록
 *
 * @since 2026-02-25
 */

exports.up = function(knex) {
  return knex.raw(`
    CREATE TABLE tbm_transfers (
      transfer_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
      transfer_date DATE NOT NULL,
      worker_id INT NOT NULL,
      source_session_id INT UNSIGNED NOT NULL,
      dest_session_id INT UNSIGNED NOT NULL,
      hours DECIMAL(4,1) NOT NULL,
      transfer_type ENUM('send','pull') NOT NULL,
      initiated_by INT NOT NULL,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      INDEX idx_date (transfer_date),
      INDEX idx_worker (worker_id, transfer_date)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
  `);
};

exports.down = function(knex) {
  return knex.raw(`DROP TABLE IF EXISTS tbm_transfers`);
};
