# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2019-02-08 18:09
from __future__ import unicode_literals

from django.db import migrations

old_name = 'series_tiempo_ar_api.apps.management.models.ReadDataJsonTask'
new_name = 'series_tiempo_ar_api.apps.management.models.IndexDataTask'


def delete_all_but_last_periodicity(apps, schema_editor):
    db_alias = schema_editor.connection.alias

    Stage = apps.get_model('django_datajsonar', 'Stage')

    Stage.objects.using(db_alias).filter(task=old_name).update(task=new_name)


def revert(apps, schema_editor):
    db_alias = schema_editor.connection.alias

    Stage = apps.get_model('django_datajsonar', 'Stage')

    Stage.objects.using(db_alias).filter(task=new_name).update(task=old_name)


class Migration(migrations.Migration):

    dependencies = [
        ('management', '0001_auto_20190408_0958'),
    ]

    operations = [
        migrations.RunPython(delete_all_but_last_periodicity, revert)
    ]
