Init mongopatcher for the application

    :param app: :class:`flask.Flask` app to initialize
    :param db: :class:`pymongo.MongoClient` to work on

    .. note: This function must be called before using ``patcher_manager``

def init_patcher(app, db):
    """
    Init mongopatcher for the application

    :param app: :class:`flask.Flask` app to initialize
    :param db: :class:`pymongo.MongoClient` to work on

    .. note: This function must be called before using ``patcher_manager``
    """
    app.config.setdefault('MONGOPATCHER_PATCHES_DIR', 'patches')
    app.config.setdefault('MONGOPATCHER_COLLECTION', 'mongopatcher')
    if not hasattr(app, 'extensions'):
        app.extensions = {}
    if 'mongopatcher' not in app.extensions:
        mp = MongoPatcher(db=db,
                          patches_dir=app.config['MONGOPATCHER_PATCHES_DIR'],
                          collection=app.config['MONGOPATCHER_COLLECTION'])
        app.extensions['mongopatcher'] = mp
    else:
        # Raise an exception if extension already initialized as
        # potentially new configuration would not be loaded.
        raise Exception('Extension already initialized')
    if 'MONGOPATCHER_DATAMODEL_VERSION' not in app.config:
        # Find last version from patches
        patches = mp.discover(app.config['MONGOPATCHER_PATCHES_DIR'])
        last_version = patches[-1].target_version if patches else '1.0.0'
        app.config.setdefault('MONGOPATCHER_DATAMODEL_VERSION', last_version)
    mp.__class__.need_upgrade = need_upgrade
    mp.app_datamodel_version = app.config['MONGOPATCHER_DATAMODEL_VERSION']
    return mp