-- Emergency SQL fix for missing related_loan_id column
-- Run this directly in your production database

-- Check if column exists first
SELECT COLUMN_NAME 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA = DATABASE() 
  AND TABLE_NAME = 'utils_notification' 
  AND COLUMN_NAME = 'related_loan_id';

-- Add the missing column if it doesn't exist
ALTER TABLE `utils_notification` 
ADD COLUMN `related_loan_id` char(32) NULL;

-- Add index for performance
ALTER TABLE `utils_notification` 
ADD KEY `utils_notification_related_loan_id_idx` (`related_loan_id`);

-- Try to add foreign key constraint (optional - may fail if referential integrity issues)
-- ALTER TABLE `utils_notification` 
-- ADD CONSTRAINT `utils_notification_related_loan_id_fk` 
-- FOREIGN KEY (`related_loan_id`) REFERENCES `loans` (`id`) ON DELETE CASCADE;

-- Verify the column was added
DESCRIBE `utils_notification`;
