# -*- coding: utf-8 -*-
# Generated by Django 1.11a1 on 2017-01-23 00:25
from __future__ import unicode_literals

from django.db import migrations


def forwards(apps, schema_editor):
    Card = apps.get_model('flashcards', 'Card')

    for card in Card.objects.all().select_related('fact', 'deck').iterator():
        if card.fact.deck_id != card.deck_id:
            raise Exception(
                "Unexpected data integrity issue with card ID {}".format(
                    card.id))

        card.owner_id = card.deck.owner_id
        card.save(update_fields=['owner_id'])


class Migration(migrations.Migration):

    dependencies = [
        ('flashcards', '0036_card_owner'),
    ]

    operations = [
        migrations.RunPython(forwards)
    ]
