β¨ Database Migration¶
These notes only apply to TruLens developments that change the database schema.
Creating a new schema revision¶
If upgrading DB, You must do this step!!
- Make desired changes to SQLAlchemy orm models in
src/core/trulens/core/database/orm.py
. - Get a database with the new changes:
rm default.sqlite
- Run
TruSession()
to create a fresh database that uses the new ORM. - Run automatic alembic revision script generator. This will generate a new python script in
src/core/trulens/core/database/migrations
. cd src/core/trulens/core/database/migrations
SQLALCHEMY_URL="sqlite:///../../../../../../default.sqlite" alembic revision --autogenerate -m "<short_description>" --rev-id "<next_integer_version>"
- Check over the automatically generated script in
src/core/trulens/core/database/migration/versions
to make sure it looks correct. - Add the version to
src/core/trulens/core/database/migrations/data.py
in the variablesql_alchemy_migration_versions
- Make any
sqlalchemy_upgrade_paths
updates insrc/core/trulens/core/database/migrations/data.py
if a backfill is necessary.
Creating a DB at the latest schema¶
If upgrading DB, You must do this step!!
Note: You must create a new schema revision before doing this
Note: Some of these instructions may be outdated and are in progress if being updated.
- Create a sacrificial OpenAI Key (this will be added to the DB and put into github; which will invalidate it upon commit)
- cd
tests/docs_notebooks/notebooks_to_test
- remove any local dbs
rm -rf default.sqlite
- run below notebooks (Making sure you also run with the most recent code in
trulens) TODO: Move these to a script
- all_tools.ipynb #
cp ../../../generated_files/all_tools.ipynb ./
- llama_index_quickstart.ipynb #
cp ../../../examples/quickstart/llama_index_quickstart.ipynb ./
- langchain-retrieval-augmentation-with-trulens.ipynb #
cp ../../../examples/vector-dbs/pinecone/langchain-retrieval-augmentation-with-trulens.ipynb ./
- Add any other notebooks you think may have possible breaking changes
- all_tools.ipynb #
- replace the last compatible db with this new db file
- Use the version you chose for --rev-id
mkdir release_dbs/sql_alchemy_<NEW_VERSION>/
cp default.sqlite release_dbs/sql_alchemy_<NEW_VERSION>/
git add release_dbs
Testing the DB¶
Run the tests with the requisite env vars.
HUGGINGFACE_API_KEY="<to_fill_out>" \
OPENAI_API_KEY="<to_fill_out>" \
PINECONE_API_KEY="<to_fill_out>" \
PINECONE_ENV="<to_fill_out>" \
HUGGINGFACEHUB_API_TOKEN="<to_fill_out>" \
python -m pytest tests/docs_notebooks -k backwards_compat