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

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


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",
            reverse_sql="select 1;",
        ),
    ]
