def _migrate_resource(instance, migrations, version=''):
    """
    Migrate a resource instance

    Subresources are migrated first, then the resource is recursively migrated

    :param instance: a perch.Document instance
    :param migrations: the migrations for a resource
    :param version: the current resource version to migrate
    """
    if version not in migrations:
        return instance

    instance = _migrate_subresources(
        instance,
        migrations[version]['subresources']
    )

    for migration in migrations[version]['migrations']:
        instance = migration(instance)
        instance._resource['doc_version'] = unicode(migration.version)

        instance = _migrate_resource(
            instance,
            migrations,
            version=migration.version
        )

    return instance
Migrate a resource instance

    Subresources are migrated first, then the resource is recursively migrated

    :param instance: a perch.Document instance
    :param migrations: the migrations for a resource
    :param version: the current resource version to migrate