-- Migration: Add employee_id column to users table
-- This allows linking user accounts to employee records

-- Add employee_id column to users table
ALTER TABLE `users` 
ADD COLUMN `employee_id` int(11) NULL AFTER `site_id`,
ADD KEY `fk_user_employee` (`employee_id`),
ADD CONSTRAINT `fk_user_employee` FOREIGN KEY (`employee_id`) REFERENCES `employees` (`employee_id`) ON DELETE SET NULL;

-- Add unique constraint to ensure one user per employee (optional - uncomment if needed)
-- ALTER TABLE `users` ADD UNIQUE KEY `unique_employee_user` (`employee_id`);

