#!/usr/bin/env python
"""Add M-Pesa columns to users_branch table"""
import os
import django

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'branch_system.settings')
django.setup()

from django.db import connection

with connection.cursor() as cursor:
    # Check if columns exist
    cursor.execute("""
        SELECT COUNT(*) 
        FROM information_schema.COLUMNS 
        WHERE TABLE_SCHEMA = DATABASE() 
        AND TABLE_NAME = 'users_branch' 
        AND COLUMN_NAME = 'mpesa_shortcode'
    """)
    
    if cursor.fetchone()[0] == 0:
        print("Adding M-Pesa columns to users_branch table...")
        
        cursor.execute("""
            ALTER TABLE users_branch
            ADD COLUMN mpesa_shortcode VARCHAR(10) NULL,
            ADD COLUMN mpesa_consumer_key VARCHAR(100) NULL,
            ADD COLUMN mpesa_consumer_secret VARCHAR(100) NULL,
            ADD COLUMN mpesa_passkey VARCHAR(100) NULL
        """)
        
        print("✓ M-Pesa columns added successfully!")
    else:
        print("✓ M-Pesa columns already exist")
