# Generated by Django 2.1.11 on 2019-11-19 09:43

import django.db.models.deletion
from django.db import migrations, models


def forwards_func(apps, schema_editor):
    Route = apps.get_model("routes", "Route")
    db_alias = schema_editor.connection.alias
    for route in Route.objects.using(db_alias).all():
        route.athlete = route.owner.athlete
        route.save()


def reverse_func(apps, schema_editor):
    Route = apps.get_model("routes", "Route")
    db_alias = schema_editor.connection.alias
    for route in Route.objects.using(db_alias).all():
        route.owner = route.athlete.owner
        route.save()


class Migration(migrations.Migration):

    dependencies = [
        ("routes", "0028_merge_20191118_1350"),
    ]

    operations = [
        migrations.AddField(
            model_name="route",
            name="athlete",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="tracks",
                to="routes.Athlete",
            ),
        ),
        migrations.RunPython(forwards_func, reverse_func),
        migrations.AlterUniqueTogether(
            name="route", unique_together={("athlete", "data_source", "source_id")},
        ),
    ]

# Generated by Django 2.1.11 on 2019-11-19 09:43

import django.db.models.deletion
from django.db import migrations, models


def forwards_func(apps, schema_editor):
    Route = apps.get_model("routes", "Route")
    db_alias = schema_editor.connection.alias
    for route in Route.objects.using(db_alias).all():
        route.athlete = route.owner.athlete
        route.save()


def reverse_func(apps, schema_editor):
    Route = apps.get_model("routes", "Route")
    db_alias = schema_editor.connection.alias
    for route in Route.objects.using(db_alias).all():
        route.owner = route.athlete.owner
        route.save()


class Migration(migrations.Migration):

    dependencies = [
        ("routes", "0028_merge_20191118_1350"),
    ]

    operations = [
        migrations.AddField(
            model_name="route",
            name="athlete",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="tracks",
                to="routes.Athlete",
            ),
        ),
        migrations.RunPython(forwards_func, reverse_func),
        migrations.AlterUniqueTogether(
            name="route", unique_together={("athlete", "data_source", "source_id")},
        ),
    ]

# Generated by Django 2.1.11 on 2019-11-19 09:43