-- Adds optional approver user columns for directed approval workflow.
-- Safe to run multiple times (MySQL 8+ / MariaDB with IF NOT EXISTS support).

ALTER TABLE `EmpAbsence`
    ADD COLUMN IF NOT EXISTS `ApproverUserId` INT NULL AFTER `EnteredByUserId`,
    ADD INDEX IF NOT EXISTS `idx_emp_absence_approver_user` (`ApproverUserId`);

ALTER TABLE `EmpOvertime`
    ADD COLUMN IF NOT EXISTS `ApproverUserId` INT NULL AFTER `EnteredByUserId`,
    ADD INDEX IF NOT EXISTS `idx_emp_overtime_approver_user` (`ApproverUserId`);

ALTER TABLE `EmpBonus`
    ADD COLUMN IF NOT EXISTS `ApproverUserId` INT NULL AFTER `EnteredByUserId`,
    ADD INDEX IF NOT EXISTS `idx_emp_bonus_approver_user` (`ApproverUserId`);

ALTER TABLE `leaves`
    ADD COLUMN IF NOT EXISTS `approver_user_id` INT NULL AFTER `entered_by_user_id`,
    ADD INDEX IF NOT EXISTS `idx_leaves_approver_user` (`approver_user_id`);

ALTER TABLE `salary_advances`
    ADD COLUMN IF NOT EXISTS `approver_user_id` INT NULL AFTER `entered_by_user_id`,
    ADD INDEX IF NOT EXISTS `idx_salary_advances_approver_user` (`approver_user_id`);
