"""
setup_db.py — One-time database setup script for cPanel (no terminal required).
================================================================================
Run this ONCE after uploading the project via cPanel Setup Python App →
"Execute script" feature.

HOW TO USE via cPanel Setup Python App:
  1. Open cPanel → Setup Python App → Edit your app.
  2. Scroll to "Execute Python Script".
  3. Enter path:  /home/CPANEL_USER/your-domain.com/setup_db.py
  4. Click "Run".
  5. Check the output — all migrations will be applied.
  6. DELETE this file after running (for security).
"""
import os
import sys
import django
from pathlib import Path

# Add project root to path
BASE_DIR = Path(__file__).resolve().parent
sys.path.insert(0, str(BASE_DIR))

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
django.setup()

from django.core.management import call_command  # noqa: E402

print("=" * 50)
print("Running database migrations...")
call_command('migrate', verbosity=2)
print("=" * 50)
print("All migrations applied successfully!")
print("Now run create_admin.py to create your superuser.")
print("=" * 50)
