(cls, apps, schema_editor)
Should only be called from within a django migration.
            Calls sys.exit on failure.
Should only be called from within a django migration.
            Calls sys.exit on failure.
Should only be called from within a django migration . Calls sys . exit on failure .
def migrate_from_migration(cls, apps, schema_editor):
        """
            Should only be called from within a django migration.
            Calls sys.exit on failure.
        """
        to_migrate = cls.count_items_to_be_migrated()
        print(f"Found {to_migrate} {cls.couch_doc_type()} documents to migrate.")

        migrated = to_migrate == 0
        if migrated:
            return

        command_name = cls.__module__.split('.')[-1]
        if to_migrate < cls.AUTO_MIGRATE_ITEMS_LIMIT:
            try:
                call_command(command_name)
                remaining = cls.count_items_to_be_migrated()
                if remaining != 0:
                    migrated = False
                    print(f"Automatic migration failed, {remaining} items remain to migrate.")
                else:
                    migrated = True
            except Exception:
                traceback.print_exc()
        else:
            print("Found {} items that need to be migrated.".format(to_migrate))
            print("Too many to migrate automatically.")

        if not migrated:
            print(f"""
                A migration must be performed before this environment can be upgraded to the latest version
                of CommCareHQ. This migration is run using the management command {command_name}.
            """)
            if cls.commit_adding_migration():
                print(f"""
                Run the following commands to run the migration and get up to date:

                    commcare-cloud <env> fab setup_limited_release --set code_branch={cls.commit_adding_migration()}

                    commcare-cloud <env> django-manage --release <release created by previous command> {command_name}

                    commcare-cloud <env> deploy commcare
                """)
            sys.exit(1)
def migrate_from_migration ( cls , apps , schema_editor ) : to_migrate = cls . count_items_to_be_migrated ( ) print ( f"Found {to_migrate} {cls.couch_doc_type()} documents to migrate." ) migrated = to_migrate == 0 if migrated : return command_name = cls . __module__ . split ( '.' ) [ - 1 ] if to_migrate < cls . AUTO_MIGRATE_ITEMS_LIMIT : try : call_command ( command_name ) remaining = cls . count_items_to_be_migrated ( ) if remaining != 0 : migrated = False print ( f"Automatic migration failed, {remaining} items remain to migrate." ) else : migrated = True except Exception : traceback . print_exc ( ) else : print ( "Found {} items that need to be migrated." . format ( to_migrate ) ) print ( "Too many to migrate automatically." ) if not migrated : print ( f"""
                A migration must be performed before this environment can be upgraded to the latest version
                of CommCareHQ. This migration is run using the management command {command_name}.
            """ ) if cls . commit_adding_migration ( ) : print ( f"""
                Run the following commands to run the migration and get up to date:

                    commcare-cloud <env> fab setup_limited_release --set code_branch={cls.commit_adding_migration()}

                    commcare-cloud <env> django-manage --release <release created by previous command> {command_name}

                    commcare-cloud <env> deploy commcare
                """ ) sys . exit ( 1 )