# Generated by Django 3.2.15 on 2022-10-07 08:46

from django.db import migrations

from power_query.utils import dict_hash


def generate_hashes(apps, schema_editor):
    Dataset = apps.get_model("power_query", "Dataset")
    for dataset in Dataset.objects.all():
        arguments = dataset.info.get("arguments", {})
        query_id = dataset.query_id
        dataset.hash = dict_hash({"query": query_id, **arguments})
        dataset.save()


class Migration(migrations.Migration):
    dependencies = [
        ("power_query", "0004_migration"),
    ]

    operations = [
        migrations.RunPython(generate_hashes, migrations.RunPython.noop),
    ]
