def METHOD_NAME(ctx, verbosity, traceback, noinput, lock, no_repair, no_post_upgrade, with_nodestore):
    "Perform any pending database migrations and upgrades."
    if lock:
        from sentry.locks import locks
        from sentry.utils.locking import UnableToAcquireLock
        lock = locks.get("upgrade", duration=0, name="command_upgrade")
        try:
            with lock.acquire():
                _upgrade(
                    not noinput,
                    traceback,
                    verbosity,
                    not no_repair,
                    not no_post_upgrade,
                    with_nodestore,
                )
        except UnableToAcquireLock:
            raise click.ClickException("Unable to acquire `upgrade` lock.")
    else:
        _upgrade(
            not noinput, traceback, verbosity, not no_repair, not no_post_upgrade, with_nodestore
        )