Skip to content

Commit

Permalink
feat: Add alembic log path as env var change (#4272)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2024
1 parent 924e02f commit fb0084d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/backend/base/langflow/services/database/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ def __init__(self, settings_service: SettingsService):
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()
Expand Down Expand Up @@ -178,7 +187,7 @@ def run_migrations(self, *, fix=False) -> None:
# 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))
Expand Down
2 changes: 2 additions & 0 deletions src/backend/base/langflow/services/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fb0084d

Please sign in to comment.