# Generated by Django 3.2.13 on 2022-10-17 13:47

from django.db import migrations


def clear_nlcd2019_gwlfe_results(apps, schema_editor):
    """
    Clear the results for all scenarios belonging to GWLF-E projects made after
    the release of 1.33.0, which had incorrectly aligned NLCD19 2019 on
    2022-01-17:
    https://github.com/WikiWatershed/model-my-watershed/releases/tag/1.33.0

    These results will be recalculated with the correclty aligned NLCD19 values
    when these projects are accessed again.
    """
    Project = apps.get_model('modeling', 'Project')
    Scenario = apps.get_model('modeling', 'Scenario')

    Project.objects.filter(
        model_package='gwlfe',
        created_at__gte='2022-01-17',
    ).update(
        gis_data=None,
        mapshed_job_uuid=None,
        subbasin_mapshed_job_uuid=None,
    )

    Scenario.objects.filter(
        project__model_package='gwlfe',
        project__created_at__gte='2022-01-17',
    ).update(
        results='[]',
        modification_hash='',
    )


class Migration(migrations.Migration):

    dependencies = [
        ('modeling', '0040_clear_nlcd2019_tr55_results'),
    ]

    operations = [
        migrations.RunPython(clear_nlcd2019_gwlfe_results),
    ]

Clear out unaligned NLCD19 GWLF-E results