def test_latest_db_file():
    assert latest_db_file(["v10_log.db", "v9_log.db"]) == "v10_log.db"
    assert latest_db_file(["v9_log.db", "v10_log.db"]) == "v10_log.db"
    assert latest_db_file(["v1_log.db", "v9_log.db"]) == "v9_log.db"
    assert latest_db_file(["v9_log.db", "v1_log.db"]) == "v9_log.db"
    assert latest_db_file([]) is None

    values = ["a", ".db", "v9.db", "9_log.db", "va9_log.db", "v9a_log.db"]
    for invalid_value in values:
        with pytest.raises(AssertionError):
            latest_db_file([invalid_value])
Exemple #2
0
    def run(self):
        # First clear up any partially upgraded databases.
        #
        # A database will be partially upgraded if the process receives a
        # SIGKILL/SIGINT while executing migrations. NOTE: It's very probable
        # the content of the database remains consistent, because the upgrades
        # are executed inside a migration, however making a second copy of the
        # database does no harm.
        escaped_path = escape(str(self._current_db_filename.parent))
        paths = glob(f"{escaped_path}/v*_log.db")
        valid_db_names = filter_db_names(paths)
        delete_dbs_with_failed_migrations(valid_db_names)

        # At this point we know every file version and db version match
        # (assuming there are no concurrent runs).
        paths = glob(f"{escaped_path}/v*_log.db")
        valid_db_names = filter_db_names(paths)
        latest_db_path = latest_db_file(valid_db_names)

        # First run, there is no database file available
        if latest_db_path is None:
            return

        file_version = get_file_version(latest_db_path)

        # The latest version matches our target version, nothing to do.
        if file_version == RAIDEN_DB_VERSION:
            return

        if file_version > RAIDEN_DB_VERSION:
            raise RuntimeError(
                f"Conflicting database versions detected, latest db version is v{file_version}, "
                f"Raiden client version is v{RAIDEN_DB_VERSION}."
                f"\n\n"
                f"Running a downgraded version of Raiden after an upgrade is not supported, "
                f"because the transfers done with the new client are not understandable by the "
                f"older."
            )

        self._upgrade(
            target_file=str(self._current_db_filename),
            from_file=latest_db_path,
            from_version=file_version,
        )
Exemple #3
0
def test_latest_db_file():
    assert latest_db_file(['v10_log.db', 'v9_log.db']) == 'v10_log.db'
    assert latest_db_file(['v9_log.db', 'v10_log.db']) == 'v10_log.db'
    assert latest_db_file(['v1_log.db', 'v9_log.db']) == 'v9_log.db'
    assert latest_db_file(['v9_log.db', 'v1_log.db']) == 'v9_log.db'
    assert latest_db_file([]) is None

    values = [
        'a',
        '.db',
        'v9.db',
        '9_log.db',
        'va9_log.db',
        'v9a_log.db',
    ]
    for invalid_value in values:
        with pytest.raises(AssertionError):
            latest_db_file([invalid_value])