def METHOD_NAME(
        connection: 'DBConnection',
        global_dir: Path,
        db_filename: str,
) -> bool:
    """Maybe upgrade the global DB.
    Returns True if this is a fresh DB. In that
    case the caller should make sure to input the latest version
    and also the latest migration in the settings.
    In all other cases returns False"""
    try:
        with connection.read_ctx() as cursor:
            db_version = globaldb_get_setting_value(cursor, 'version', GLOBAL_DB_VERSION)
    except sqlite3.OperationalError:  # pylint: disable=no-member
        return True  # fresh DB -- nothing to upgrade
    if db_version < MIN_SUPPORTED_GLOBAL_DB_VERSION:
        raise ValueError(
            f'Your account was last opened by a very old version of rotki and its '
            f'globaldb version is {db_version}. To be able to use it you will need to '
            f'first use a previous version of rotki and then use this one. '
            f'Refer to the documentation for more information. '
            f'https://rotki.readthedocs.io/en/latest/usage_guide.html#upgrading-rotki-after-a-very-long-time',  # noqa: E501
        )
    if db_version > GLOBAL_DB_VERSION:
        raise ValueError(
            f'Tried to open a rotki version intended to work with GlobalDB v{GLOBAL_DB_VERSION} '
            f'but the GlobalDB found in the system is v{db_version}. Bailing ...',
        )
    for upgrade in UPGRADES_LIST:
        if db_version != upgrade.from_version:
            continue
        # start the upgrade
        to_version = upgrade.from_version + 1
        # Create a backup
        tmp_db_filename = f'{ts_now()}_global_db_v{db_version}.backup'
        tmp_db_path = global_dir / tmp_db_filename
        shutil.copyfile(global_dir / db_filename, tmp_db_path)
        with connection.write_ctx() as cursor:
            cursor.execute(
                'INSERT OR REPLACE INTO settings(name, value) VALUES(?, ?)',
                ('ongoing_upgrade_from_version', str(upgrade.from_version)),
            )
        try:
            upgrade.function(connection)
        except BaseException as e:
            # Problem .. restore DB backup, log all info and bail out
            error_message = (
                f'Failed at global DB upgrade from version {upgrade.from_version} to '
                f'{to_version}: {e!s}'
            )
            stacktrace = traceback.format_exc()
            log.error(f'{error_message}\n{stacktrace}')
            shutil.copyfile(tmp_db_path, global_dir / db_filename)
            raise ValueError(error_message) from e
        # single upgrade succesfull
        with connection.write_ctx() as write_cursor:
            write_cursor.execute(
                'DELETE FROM settings WHERE name=?',
                ('ongoing_upgrade_from_version',),
            )
            write_cursor.execute(
                'INSERT OR REPLACE INTO settings(name, value) VALUES(?, ?)',
                ('version', str(to_version)),
            )
            db_version = to_version
    return False  # not fresh DB