#!/usr/bin/env python3
"""
Migration Deployment Script for Today's Updates (08-01-2026)
This script contains all migration codes created today for online server deployment.
"""

import os
import sys
import django
from django.core.management import execute_from_command_line

# Add the project directory to Python path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

# Setup Django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings_production')
django.setup()

def run_migrations():
    """Execute all migrations created today in correct order"""
    
    migrations_today = [
        # Jobs app migrations (created today)
        ('jobs', '0002_job_abroad_job_category_job_job_role'),
        ('jobs', '0003_job_industry_type'),
        ('jobs', '0004_alter_jobapplication_cover_letter'),
        ('jobs', '0005_job_currency'),
        ('jobs', '0006_job_job_category'),
        ('jobs', '0010_remove_currency_icon'),
        ('jobs', '0013_remove_currency_icon_and_more'),
        
        # Subscriptions app migrations (created today)
        ('subscriptions', '0012_fix_missing_payment_user_column'),
    ]
    
    print("=" * 60)
    print("DEPLOYING TODAY'S MIGRATIONS (08-01-2026)")
    print("=" * 60)
    
    for app, migration in migrations_today:
        print(f"\n🔄 Applying {app}.{migration}...")
        try:
            execute_from_command_line(['manage.py', 'migrate', app, migration])
            print(f"✅ Successfully applied {app}.{migration}")
        except Exception as e:
            print(f"❌ Error applying {app}.{migration}: {str(e)}")
            return False
    
    print("\n" + "=" * 60)
    print("✅ ALL TODAY'S MIGRATIONS DEPLOYED SUCCESSFULLY!")
    print("=" * 60)
    return True

if __name__ == '__main__':
    success = run_migrations()
    sys.exit(0 if success else 1)