From fb0084d4789fc2bfc0b31be9bf231a787e496b0c Mon Sep 17 00:00:00 2001 From: Devin Bost Date: Tue, 29 Oct 2024 05:28:41 -0500 Subject: [PATCH] feat: Add alembic log path as env var change (#4272) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added alembic log path as env var change * [autofix.ci] apply automated fixes * Improved platform independence of path check * fix: arg-type mypy error --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Ítalo Johnny --- .../base/langflow/services/database/service.py | 11 ++++++++++- src/backend/base/langflow/services/settings/base.py | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/services/database/service.py b/src/backend/base/langflow/services/database/service.py index 63892797c..5e8a33dc6 100644 --- a/src/backend/base/langflow/services/database/service.py +++ b/src/backend/base/langflow/services/database/service.py @@ -44,6 +44,15 @@ class DatabaseService(Service): self.script_location = langflow_dir / "alembic" self.alembic_cfg_path = langflow_dir / "alembic.ini" self.engine = self._create_engine() + alembic_log_file = self.settings_service.settings.alembic_log_file + + # Check if the provided path is absolute, cross-platform. + if Path(alembic_log_file).is_absolute(): + # Use the absolute path directly. + self.alembic_log_path = Path(alembic_log_file) + else: + # Construct the path using the langflow directory. + self.alembic_log_path = Path(langflow_dir) / alembic_log_file def reload_engine(self) -> None: self.engine = self._create_engine() @@ -178,7 +187,7 @@ class DatabaseService(Service): # which is a buffer # I don't want to output anything # subprocess.DEVNULL is an int - with (self.script_location / "alembic.log").open("w", encoding="utf-8") as buffer: + with self.alembic_log_path.open("w", encoding="utf-8") as buffer: alembic_cfg = Config(stdout=buffer) # alembic_cfg.attributes["connection"] = session alembic_cfg.set_main_option("script_location", str(self.script_location)) diff --git a/src/backend/base/langflow/services/settings/base.py b/src/backend/base/langflow/services/settings/base.py index cdbdccde3..3d2cc6a77 100644 --- a/src/backend/base/langflow/services/settings/base.py +++ b/src/backend/base/langflow/services/settings/base.py @@ -157,6 +157,8 @@ class Settings(BaseSettings): """The log level for Langflow.""" log_file: str | None = "logs/langflow.log" """The path to log file for Langflow.""" + alembic_log_file: str = "alembic/alembic.log" + """The path to log file for Alembic for SQLAlchemy.""" frontend_path: str | None = None """The path to the frontend directory containing build files. This is for development purposes only..""" open_browser: bool = False