feat: Add alembic log path as env var change (#4272)

* 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 <italojohnnydosanjos@gmail.com>
This commit is contained in:
Devin Bost 2024-10-29 05:28:41 -05:00 committed by GitHub
commit fb0084d478
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View file

@ -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))

View file

@ -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