# Generated by Django 3.2.5 on 2021-09-30 17:46

from django.db import migrations
from bookwyrm.settings import DOMAIN


def remove_self_connector(app_registry, schema_editor):
    """set the new physical format field based on existing format data"""
    db_alias = schema_editor.connection.alias
    app_registry.get_model("bookwyrm", "Connector").objects.using(db_alias).filter(
        connector_file="self_connector"
    ).delete()


def reverse(app_registry, schema_editor):
    """doesn't need to do anything"""
    db_alias = schema_editor.connection.alias
    model = app_registry.get_model("bookwyrm", "Connector")
    model.objects.using(db_alias).create(
        identifier=DOMAIN,
        name="Local",
        local=True,
        connector_file="self_connector",
        base_url=f"https://{DOMAIN}",
        books_url=f"https://{DOMAIN}/book",
        covers_url=f"https://{DOMAIN}/images/",
        search_url=f"https://{DOMAIN}/search?q=",
        isbn_search_url=f"https://{DOMAIN}/isbn/",
        priority=1,
    )


class Migration(migrations.Migration):

    dependencies = [
        ("bookwyrm", "0101_auto_20210929_1847"),
    ]

    operations = [
        migrations.RunPython(remove_self_connector, reverse),
    ]
