-- Fix loans migration dependency issue
-- Run this SQL directly in your MySQL database

-- Remove the problematic migration
DELETE FROM django_migrations WHERE app = 'loans' AND name = '0018_add_rollover_date_field';

-- Add 0017 if it doesn't exist
INSERT IGNORE INTO django_migrations (app, name, applied) VALUES 
('loans', '0017_merge_20251002_0238', NOW());

-- Re-add 0018 after 0017
INSERT INTO django_migrations (app, name, applied) VALUES 
('loans', '0018_add_rollover_date_field', NOW());

-- Ensure rollover_date column exists
ALTER TABLE rollover_requests 
ADD COLUMN IF NOT EXISTS rollover_date DATE NULL 
COMMENT 'Preferred rollover date';

-- Verify the fix
SELECT 'Loans migration dependency fixed!' as status;
SELECT app, name, applied FROM django_migrations WHERE app = 'loans' AND name LIKE '%0017%' OR name LIKE '%0018%' ORDER BY name;
