diff --git a/src/backend/langflow/database/base.py b/src/backend/langflow/database/base.py index a0efcdd2a..37fe00255 100644 --- a/src/backend/langflow/database/base.py +++ b/src/backend/langflow/database/base.py @@ -6,6 +6,7 @@ if settings.database_url.startswith("sqlite"): connect_args = {"check_same_thread": False} else: connect_args = {} + engine = create_engine(settings.database_url, connect_args=connect_args) @@ -13,6 +14,15 @@ def create_db_and_tables(): logger.debug("Creating database and tables") SQLModel.metadata.create_all(engine) logger.debug("Database and tables created") + # Now check if the table Flow exists, if not, something went wrong + # and we need to create the tables again. + from sqlalchemy import inspect + + inspector = inspect(engine) + if "flow" not in inspector.get_table_names(): + logger.error("Something went wrong creating the database and tables.") + logger.error("Please check your database settings.") + raise RuntimeError("Something went wrong creating the database and tables.") def get_session(): diff --git a/src/backend/langflow/lcserve.py b/src/backend/langflow/lcserve.py index 9419fbe70..de1d2806d 100644 --- a/src/backend/langflow/lcserve.py +++ b/src/backend/langflow/lcserve.py @@ -1,16 +1,7 @@ # This file is used by lc-serve to load the mounted app and serve it. -from pathlib import Path +from langflow.main import setup_app +from langflow.utils.logger import configure -from fastapi.staticfiles import StaticFiles - -from langflow.main import create_app - -app = create_app() -path = Path(__file__).parent -static_files_dir = path / "frontend" -app.mount( - "/", - StaticFiles(directory=static_files_dir, html=True), - name="static", -) +configure(log_level="DEBUG") +app = setup_app() diff --git a/src/backend/langflow/main.py b/src/backend/langflow/main.py index e937931d6..8831b8e0f 100644 --- a/src/backend/langflow/main.py +++ b/src/backend/langflow/main.py @@ -61,7 +61,7 @@ def setup_static_files(app: FastAPI, static_files_dir: Path): # app = create_app() # setup_static_files(app, static_files_dir) -def setup_app(static_files_dir: Optional[Path]) -> FastAPI: +def setup_app(static_files_dir: Optional[Path] = None) -> FastAPI: """Setup the FastAPI app.""" # get the directory of the current file if not static_files_dir: