def insert_app(self, app: app_schema.AppDefinition) -> types_schema.AppID:
        """See [DB.insert_app][trulens.core.database.base.DB.insert_app]."""

        # TODO: thread safety

        with self.session.begin() as session:
            if (
                _app := session.query(self.orm.AppDefinition)
                .filter_by(app_id=app.app_id)
                .first()
            ):
                _app.app_json = app.model_dump_json()
            else:
                _app = self.orm.AppDefinition.parse(
                    app, redact_keys=self.redact_keys
                )
                session.merge(_app)  # .add was not thread safe

            logger.info(
                "%s added app %s", text_utils.UNICODE_CHECK, _app.app_id
            )

            return _app.app_id
See [DB.insert_app][trulens.core.database.base.DB.insert_app].
src/core/trulens/core/database/sqlalchemy.py