Skip to content

trulens.core.database.legacy.migration

trulens.core.database.legacy.migration

This is pre-sqlalchemy db migration. This file should not need changes. It is here for backwards compatibility of oldest TruLens versions.

Attributes

logger module-attribute

logger = getLogger(__name__)

How to make a db migrations:

  1. Create a compatibility DB (checkout the last pypi rc branch https://github.com/truera/trulens/tree/releases/rc-trulens-X.x.x/): In trulens/tests/docs_notebooks/notebooks_to_test remove any local dbs

    • rm rf default.sqlite run below notebooks (Making sure you also run with the same X.x.x version trulens)
    • all_tools.ipynb # cp cp ../generated_files/all_tools.ipynb ./
    • llama_index_quickstart.ipynb # cp frameworks/llama_index/llama_index_quickstart.ipynb ./
    • langchain-retrieval-augmentation-with-trulens.ipynb # cp vector-dbs/pinecone/langchain-retrieval-augmentation-with-trulens.ipynb ./
    • Add any other notebooks you think may have possible breaking changes replace the last compatible db with this new db file
    • See the last COMPAT_VERSION: compatible version in leftmost below: migration_versions
    • mv default.sqlite trulens/release_dbs/COMPAT_VERSION/default.sqlite
  2. Do Migration coding

  3. Update init.py with the new version
  4. The upgrade methodology is determined by this data structure upgrade_paths = { # from_version: (to_version,migrate_function) "0.1.2": ("0.2.0", migrate_0_1_2), "0.2.0": ("0.3.0", migrate_0_2_0) }
  5. add your version to the version list: migration_versions: list = [YOUR VERSION HERE,...,"0.3.0", "0.2.0", "0.1.2"]

  6. To Test

  7. replace your db file with an old version db first and see if the session.migrate_database() works.

  8. Add a DB file for testing new breaking changes (Same as step 1: but with your new version)

  9. Do a sys.path.insert(0,TRULENS_PATH) to run with your version

Classes

UnknownClass

Bases: BaseModel

Functions
unknown_method
unknown_method()

This is a placeholder put into the database in place of methods whose information was not recorded in earlier versions of trulens.

Functions

_update_db_json_col

_update_db_json_col(
    db,
    table: str,
    old_entry: tuple,
    json_db_col_idx: int,
    new_json: dict,
)

Replaces an old json serialized db column with a migrated/new one.

PARAMETER DESCRIPTION
db

the db object

TYPE: DB

table

the table to update (from the current DB)

TYPE: str

old_entry

the db tuple to update

TYPE: tuple

json_db_col_idx

the tuple idx to update

TYPE: int

new_json

the new json object to be put in the D

TYPE: dict

_parse_version

_parse_version(version_str: str) -> List[str]

Takes a version string and returns a list of major, minor, patch.

PARAMETER DESCRIPTION
-

a version string

TYPE: version_str (str

RETURNS DESCRIPTION
list

[major, minor, patch] strings

TYPE: List[str]

_get_compatibility_version

_get_compatibility_version(version: str) -> str

Gets the db version that the pypi version is compatible with.

PARAMETER DESCRIPTION
-

a pypi version

TYPE: version (str

RETURNS DESCRIPTION
str
  • str: a backwards compat db version

_migration_checker

_migration_checker(db, warn: bool = False) -> None

Checks whether this db, if pre-populated, is compatible with this pypi version.

PARAMETER DESCRIPTION
-

the db object to check

TYPE: db (DB

-

if warn is False, then a migration issue will raise an exception, otherwise allow passing but only warn. Defaults to False.

TYPE: warn (bool

commit_migrated_version

commit_migrated_version(db, version: str) -> None

After a successful migration, update the DB meta version

PARAMETER DESCRIPTION
db

the db object

TYPE: DB

version

The version string to set this DB to

TYPE: str

_upgrade_possible

_upgrade_possible(compat_version: str) -> bool

Checks the upgrade paths to see if there is a valid migration from the DB to the current pypi version

PARAMETER DESCRIPTION
-

the current db version.

TYPE: compat_version (str

RETURNS DESCRIPTION
bool
  • bool: True if there is an upgrade path. False if not.

_check_needs_migration

_check_needs_migration(version: str, warn=False) -> None

Checks whether the from DB version can be updated to the current DB version.

PARAMETER DESCRIPTION
-

the pypi version

TYPE: version (str

-

if warn is False, then a migration issue will raise an exception, otherwise allow passing but only warn. Defaults to False.

TYPE: warn (bool

_serialization_asserts

_serialization_asserts(db) -> None

After a successful migration, Do some checks if serialized jsons are loading properly.

PARAMETER DESCRIPTION
db

the db object

TYPE: DB

migrate

migrate(db) -> None

Migrate a db to the compatible version of this pypi version

PARAMETER DESCRIPTION
db

the db object

TYPE: DB