# ONE-LINER COMMAND TO FIX ALL MISSING COLUMNS
# Run this in your cPanel terminal/SSH

cd /home/yourusername/public_html/branch-system && python3 -c "
import os, django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'branch_system.settings')
django.setup()
from django.db import connection
with connection.cursor() as cursor:
    cursor.execute('SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = \"portfolio_assignments\"')
    existing = [row[0] for row in cursor.fetchall()]
    columns = {'is_active': 'BOOLEAN DEFAULT TRUE', 'unassigned_date': 'DATETIME NULL', 'reason': 'TEXT NULL'}
    for col, defn in columns.items():
        if col not in existing:
            cursor.execute(f'ALTER TABLE portfolio_assignments ADD COLUMN {col} {defn}')
            print(f'Added {col}')
        else:
            print(f'{col} exists')
" && python3 manage.py migrate users 0018 --fake --noinput && echo "ALL COLUMNS FIXED!"
