#!/usr/bin/env python
"""
Create and apply missing migrations for all apps
"""
import os
import django

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'branch_system.settings')
django.setup()

from django.core.management import call_command

print("=" * 80)
print("CREATING AND APPLYING MISSING MIGRATIONS")
print("=" * 80)

try:
    # Create new migrations
    print("\nStep 1: Creating new migrations...")
    print("-" * 80)
    call_command('makemigrations', verbosity=2)
    
    print("\n" + "=" * 80)
    print("Step 2: Applying migrations...")
    print("-" * 80)
    call_command('migrate', verbosity=2)
    
    print("\n" + "=" * 80)
    print("✓ SUCCESS - All migrations created and applied!")
    print("=" * 80)
    print("\nYou can now access the dashboard.")
    
except Exception as e:
    print("\n" + "=" * 80)
    print("✗ ERROR")
    print("=" * 80)
    print(f"Error: {str(e)}")
    print("\nTry running manually:")
    print("  python manage.py makemigrations")
    print("  python manage.py migrate")
