from django.core.management import call_command
from django.db import migrations

from corehq.privileges import RELEASE_MANAGEMENT
from corehq.util.django_migrations import skip_on_fresh_install


@skip_on_fresh_install
def _add_release_management_to_enterprise(apps, schema_editor):
    call_command(
        'cchq_prbac_grandfather_privs',
        RELEASE_MANAGEMENT,
        skip_edition='Paused,Community,Standard,Pro,Advanced',
        noinput=True,
    )


class Migration(migrations.Migration):
    dependencies = [
        ('accounting', '0061_remove_enterprise_v1'),
    ]

    operations = [
        migrations.RunPython(_add_release_management_to_enterprise),
    ]

@@ -456,16 +456,266 @@
     )%0A%0A%0A
+def _reverse():%0A    call_command(%0A        'cchq_prbac_revoke_privs',%0A        RELEASE_MANAGEMENT,%0A        skip_edition='Paused,Community,Standard,Pro,Advanced',%0A        delete_privs=False,%0A        check_privs_exist=True,%0A        noinput=True,%0A    )%0A%0A%0A
 class Mi
@@ -874,16 +874,29 @@
 nPython(
+%0A            
 _add_rel
@@ -924,16 +924,60 @@
 terprise
+,%0A            reverse_code=_reverse%0A        
 ),%0A    %5D

add reverse for migration