def update_app_metadata(
        self, app_id: types_schema.AppID, metadata: Dict[str, Any]
    ) -> Optional[app_schema.AppDefinition]:
        """See [DB.update_app_metadata][trulens.core.database.base.DB.update_app_metadata]."""

        def nested_update(metadata: dict, update: dict):
            for k, v in update.items():
                if isinstance(v, dict) and k in metadata:
                    nested_update(metadata[k], v)
                else:
                    metadata[k] = v

        with self.session.begin() as session:
            if (
                _app := session.query(self.orm.AppDefinition)
                .filter_by(app_id=app_id)
                .first()
            ):
                app_json = json.loads(_app.app_json)
                if "metadata" not in app_json:
                    app_json["metadata"] = {}
                nested_update(app_json["metadata"], metadata)
                _app.app_json = json.dumps(app_json)
See [DB.update_app_metadata][trulens.core.database.base.DB.update_app_metadata].
src/core/trulens/core/database/sqlalchemy.py