# -*- coding: utf-8 -*-
# Generated by Django 1.11.13 on 2018-08-08 19:45
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('osf', '0125_auto_20180808_1942'),
    ]

    operations = [
        migrations.RunSQL(
            [
                """
                UPDATE auth_group AG0
                SET name = (
                            SELECT 'reviews_' ||
                                CASE
                                WHEN P.type = 'osf.preprintprovider'
                                    THEN 'preprint'
                                WHEN P.type = 'osf.collectionprovider'
                                    THEN 'collection'
                                WHEN P.type = 'osf.registrationprovider'
                                    THEN 'registration'
                                END || '_' || id || '_' || split_part(AG0.name, '_', 3)
                            FROM osf_abstractprovider P
                            WHERE _id = split_part(AG0.name, '_', 2)
                )
                WHERE AG0.name LIKE 'reviews_%';
                """
            ], [
                """
                UPDATE auth_group AG0
                SET name = (
                            SELECT 'reviews_' || P._id || '_' || split_part(AG0.name, '_', 4)
                                FROM osf_abstractprovider P
                            WHERE id = split_part(AG0.name, '_', 3)::INT
                )
                WHERE AG0.name LIKE 'reviews_%';
                """
            ]
        )
    ]
