# One-liner command to fix the database schema issue on cPanel production
# Run this command in your cPanel terminal or 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\" AND COLUMN_NAME = \"unassigned_date\"')
    if not cursor.fetchone():
        cursor.execute('ALTER TABLE portfolio_assignments ADD COLUMN unassigned_date DATETIME NULL')
        print('Column added')
    else:
        print('Column exists')
" && python3 manage.py migrate users 0018 --fake --noinput && echo "Database fix completed!"
