def _get_sql_alchemy_compatibility_version(version: int) -> int:
    """Gets the last compatible version of a DB that needed data migration.

    Args:
        version: The alembic version

    Returns:
        int: An alembic version of the oldest compatible DB
    """

    for candidate_version in sorted(
        sql_alchemy_migration_versions, reverse=True
    ):
        if candidate_version <= version:
            return candidate_version
    raise ValueError(
        f"The version given {version} is not compatible with any known version! Known versions: {sql_alchemy_migration_versions}"
    )
Gets the last compatible version of a DB that needed data migration.

    Args:
        version: The alembic version

    Returns:
        int: An alembic version of the oldest compatible DB
    
src/core/trulens/core/database/migrations/data.py