#!/bin/bash

# One-liner deployment for rollover enhancements
# This bypasses Django migrations and adds the column directly

echo "=== Quick Rollover Deployment ==="

# Navigate to project directory
cd /home/acbptxvs/public_html/branchbusinessadvance.co.ke

# Activate virtual environment
source /home/acbptxvs/virtualenv/public_html/branchbusinessadvance.co.ke/3.13/bin/activate

# Add rollover_date column directly using Django shell
python -c "
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:
    try:
        cursor.execute('ALTER TABLE rollover_requests ADD COLUMN rollover_date DATE NULL COMMENT \"Preferred rollover date\"')
        print('SUCCESS: rollover_date column added!')
    except Exception as e:
        if 'Duplicate column name' in str(e):
            print('SUCCESS: rollover_date column already exists!')
        else:
            print(f'ERROR: {e}')
            exit(1)
"

echo "=== Deployment Complete ==="
echo "The rollover enhancements are now ready!"
echo "Features available:"
echo "  - Enhanced rollover form with date field"
echo "  - Complete History button in client popup"
echo "  - Complete History button in loan detail pages"
