# Generated by Django 2.2.4 on 2019-09-02 17:36
from django.db import migrations
from django.contrib.gis.geos import Point


def move_bike_position_to_location(apps, schema_editor):
    Bike = apps.get_model("bikesharing", "Bike")
    Location = apps.get_model("bikesharing", "Location")
    for bike in Bike.objects.all():
        loc = Location.objects.create(
            bike=bike,
            geo=bike.current_position,
            source="LO",
            reported_at=bike.last_reported,
        )
        loc.save()
        bike.current_position = Point(0, 0, srid=4326)
        bike.save()


class Migration(migrations.Migration):

    dependencies = [
        ("bikesharing", "0010_location"),
    ]

    operations = [
        migrations.RunPython(move_bike_position_to_location),
    ]