# Generated by Django 2.2.6 on 2019-12-13 11:56

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("models", "10999_add_principaluserid_to_resources"),
    ]

    operations = [
        migrations.RunSQL(
            sql="update resource_instances set principaluser_id = {}".format(
                settings.DEFAULT_RESOURCE_IMPORT_USER["userid"]
            ),
            reverse_sql="select 1;",
        ),
        migrations.RunSQL(
            sql="update resource_instances a set principaluser_id = b.userid::integer from (select userid, resourceinstanceid from edit_log where edittype = 'create' and userid != '' and userid is not null)b where a.resourceinstanceid::text = b.resourceinstanceid and b.userid::integer in (select id from auth_user)",
            reverse_sql="select 1;",
        ),
        # Moved from 10799_geojsongeometry_featureid in 7.6.2
        # because RunSQL that calls refresh_geojson_geometries() needs to be
        # fully isolated in its own migration file, and it was found too late
        # to insert a new file into the migration history.
        migrations.AddField(
            model_name="geojsongeometry",
            name="featureid",
            field=models.UUIDField(blank=True, null=True, serialize=False),
        ),
    ]
