# Generated by Django 5.2 on 2025-02-17
from django.db import migrations

OPENROUTER_BASE = "https://openrouter.ai/api/v1"


def _clear_openrouter_persistent_api_base(apps, schema_editor):
    PersistentModelEndpoint = apps.get_model("api", "PersistentModelEndpoint")
    LLMProvider = apps.get_model("api", "LLMProvider")

    provider = LLMProvider.objects.filter(key="openrouter").first()
    if not provider:
        return

    qs = PersistentModelEndpoint.objects.filter(provider=provider, api_base=OPENROUTER_BASE)
    for endpoint in qs:
        endpoint.api_base = ""
        endpoint.save(update_fields=["api_base"])


class Migration(migrations.Migration):

    dependencies = [
        ("api", "0195_fix_openrouter_browser_models"),
    ]

    operations = [
        migrations.RunPython(_clear_openrouter_persistent_api_base, migrations.RunPython.noop),
    ]
