#!/usr/bin/env python3
"""
Quick fix for missing registration_fee_receipt_number column
Run this script to add the missing column immediately
"""

import os
import sys
import django
from django.db import connection

# Setup Django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'branch_system.settings_production')
django.setup()

def fix_missing_column():
    """Add the missing registration_fee_receipt_number column"""
    print("🔧 Fixing missing registration_fee_receipt_number column...")
    
    try:
        with connection.cursor() as cursor:
            # Check if column exists
            cursor.execute("""
                SELECT COLUMN_NAME 
                FROM INFORMATION_SCHEMA.COLUMNS 
                WHERE TABLE_SCHEMA = DATABASE() 
                AND TABLE_NAME = 'users' 
                AND COLUMN_NAME = 'registration_fee_receipt_number'
            """)
            
            if not cursor.fetchone():
                print("Adding registration_fee_receipt_number column...")
                cursor.execute("""
                    ALTER TABLE users 
                    ADD COLUMN registration_fee_receipt_number VARCHAR(100) NULL
                """)
                print("✅ SUCCESS: Added registration_fee_receipt_number column")
            else:
                print("✅ SUCCESS: registration_fee_receipt_number column already exists")
                
        print("🎉 Column fix completed successfully!")
        return True
        
    except Exception as e:
        print(f"❌ ERROR: {e}")
        return False

if __name__ == "__main__":
    success = fix_missing_column()
    sys.exit(0 if success else 1)