#!/usr/bin/env python3
# migrate_ai_chat.py — palaid cPanel Execute python script
import sys, os
from pathlib import Path

base = Path("/home2/melgalis/agent_backend")
sys.path.insert(0, str(base))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")

env = base / ".env"
if env.exists():
    for line in env.read_text().splitlines():
        line = line.strip()
        if line and not line.startswith("#") and "=" in line:
            k, _, v = line.partition("=")
            os.environ.setdefault(k.strip(), v.strip())

import django
django.setup()

from django.core.management import call_command

print("=" * 45)
print("SOLIS 1: makemigrations ai_chat")
print("=" * 45)
call_command("makemigrations", "ai_chat")

print("\n" + "=" * 45)
print("SOLIS 2: migrate")
print("=" * 45)
call_command("migrate")

print("\n✅ PABEIGTS!")
