<commit_before>from corehq.apps.cleanup.management.commands.populate_sql_model_from_couch_model import PopulateSQLCommand
from corehq.apps.users.models import UserRole, Permissions
from corehq.apps.users.models_sql import (
    migrate_role_assignable_by_to_sql,
    migrate_role_permissions_to_sql,
    SQLUserRole,
)


class Command(PopulateSQLCommand):
    @classmethod
    def couch_db_slug(cls):
        return "users"

    @classmethod
    def couch_doc_type(self):
        return 'UserRole'

    @classmethod
    def sql_class(self):
        from corehq.apps.users.models import SQLUserRole
        return SQLUserRole

    @classmethod
    def commit_adding_migration(cls):
        return "TODO: add once the PR adding this file is merged"

    @classmethod
    def diff_couch_and_sql(cls, couch, sql):
        diffs = []
        for field in UserRole._migration_get_fields():
            diffs.append(cls.diff_attr(field, couch, sql))

        couch_permissions = {
            info.name: info
            for info in Permissions.wrap(couch["permissions"]).to_list()
        }
        sql_permissions = {
            info.name: info
            for info in sql.permissions.to_list()
        }

        for name in sorted(set(couch_permissions) | set(sql_permissions)):
            couch_permission = couch_permissions.get(name)
            diffs.append(cls.diff_attr(
                "allow",<commit_msg>add commit reference to populate_user_role migration<commit_after>from corehq.apps.cleanup.management.commands.populate_sql_model_from_couch_model import PopulateSQLCommand
from corehq.apps.users.models import UserRole, Permissions
from corehq.apps.users.models_sql import (
    migrate_role_assignable_by_to_sql,
    migrate_role_permissions_to_sql,
)


class Command(PopulateSQLCommand):
    @classmethod
    def couch_db_slug(cls):
        return "users"

    @classmethod
    def couch_doc_type(self):
        return 'UserRole'

    @classmethod
    def sql_class(self):
        from corehq.apps.users.models import SQLUserRole
        return SQLUserRole

    @classmethod
    def commit_adding_migration(cls):
        return "4f5a5ef0a9b5ef9873a9b2dce5646d7aa881c416"

    @classmethod
    def diff_couch_and_sql(cls, couch, sql):
        diffs = []
        for field in UserRole._migration_get_fields():
            diffs.append(cls.diff_attr(field, couch, sql))

        couch_permissions = {
            info.name: info
            for info in Permissions.wrap(couch["permissions"]).to_list()
        }
        sql_permissions = {
            info.name: info
            for info in sql.permissions.to_list()
        }

        for name in sorted(set(couch_permissions) | set(sql_permissions)):
            couch_permission = couch_permissions.get(name)
            diffs.append(cls.diff_attr(
                "allow",
{'fraction_non_alphanumeric': 0.07892882311486962, 'fraction_numerical': 0.00810429880197322, 'mean_word_length': 2.7853333333333334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2558378', 'n_tokens_mistral': 893, 'n_tokens_neox': 877, 'n_words': 166}