# Rollover Status Update Scripts

This directory contains scripts to update rolled over loan statuses on your production server to follow the new pattern.

## What These Scripts Do

- Update existing rolled over loans to have 'active' application status instead of 'approved'
- Ensure consistency across all rolled over loans
- Create database backups before making changes
- Provide detailed logging of all operations

## Files Included

1. **`cpanel_update_rollover_status.py`** - Main Python script
2. **`update_rollover_status.sh`** - Bash wrapper script
3. **`ROLLOVER_STATUS_UPDATE_README.md`** - This instruction file

## How to Use

### Option 1: Using the Bash Script (Recommended)

1. Upload all files to your cPanel file manager in your Django project root directory
2. Open cPanel Terminal
3. Navigate to your project directory:
   ```bash
   cd /home/yourusername/public_html/yourproject
   ```
4. Make the script executable:
   ```bash
   chmod +x update_rollover_status.sh
   ```
5. Run the script:
   ```bash
   ./update_rollover_status.sh
   ```

### Option 2: Using Python Directly

1. Upload `cpanel_update_rollover_status.py` to your Django project root
2. Open cPanel Terminal
3. Navigate to your project directory
4. Run the script:
   ```bash
   python3 cpanel_update_rollover_status.py
   # or
   python cpanel_update_rollover_status.py
   ```

## What Happens When You Run the Script

1. **Backup Creation**: Creates a database backup before making changes
2. **Django Setup**: Initializes Django environment
3. **Status Update**: Updates all rolled over loans to have 'active' application status
4. **Verification**: Checks that all updates were applied correctly
5. **Logging**: Creates detailed logs in `rollover_status_update.log`

## Expected Output

```
🎯 cPanel Rollover Status Update Script
========================================
✅ Using Python command: python3
📦 Creating backup of database...
✅ Database backup created: rollover_backup_20241020_143022.sql
🚀 Running rollover status update...
✅ Django environment setup successfully
📊 Found 5 rolled over loans to check
🔄 Processing loan 1/5: LOAN-000001
   ✅ Updated application status from 'approved' to 'active'
...
🎉 Script completed successfully!
```

## Safety Features

- **Database Backup**: Automatically creates a backup before making changes
- **Transaction Safety**: Uses Django transactions to ensure data integrity
- **Detailed Logging**: All operations are logged for audit purposes
- **Verification**: Checks that updates were applied correctly

## Troubleshooting

### If the script fails:

1. Check the log file: `rollover_status_update.log`
2. Verify Django is properly configured
3. Check database permissions
4. Restore from backup if needed

### Common Issues:

- **Python not found**: Make sure Python 3 is installed
- **Django setup failed**: Check your Django settings
- **Database connection failed**: Verify database credentials

## After Running the Script

1. **Verify Changes**: Check your Django admin to see the updated statuses
2. **Test Functionality**: Test the rollover functionality to ensure it works
3. **Keep Backup**: Keep the backup file for safety
4. **Monitor Logs**: Check the log file for any issues

## Rollback (If Needed)

If you need to rollback the changes:

1. Stop your Django application
2. Restore from the backup:
   ```bash
   mysql your_database_name < rollover_backup_YYYYMMDD_HHMMSS.sql
   ```
3. Restart your Django application

## Support

If you encounter any issues:

1. Check the log file for detailed error messages
2. Verify your Django project is properly configured
3. Ensure you have the necessary database permissions
4. Contact your system administrator if needed

---

**Important**: Always test on a staging environment first before running on production!
