code: def _migrate_subresource(subresource, parent, migrations):
      
      for key, doc in getattr(parent, subresource.parent_key, {}).items():
          for migration in migrations['migrations']:
              instance = migration(subresource(id=key, **doc))
              parent._resource['doc_version'] = unicode(migration.version)
  
              instance = _migrate_subresources(
                  instance,
                  migrations['subresources']
              )
  
          doc = instance._resource
          doc.pop('id', None)
          doc.pop(instance.resource_type + '_id', None)
  
          getattr(parent, subresource.parent_key)[key] = doc
  
      return parent
docs: Migrate a resource's subresource
  
      :param subresource: the perch.SubResource instance
      :param parent: the parent perch.Document instance
      :param migrations: the migrations for a resource