diff --git a/src/backend/langflow/alembic.ini b/src/backend/langflow/alembic.ini index cba482993..379661422 100644 --- a/src/backend/langflow/alembic.ini +++ b/src/backend/langflow/alembic.ini @@ -63,7 +63,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne # This is the path to the db in the root of the project. # When the user runs the Langflow the database url will # be set dinamically. -# sqlalchemy.url = sqlite:///../../../langflow.db +sqlalchemy.url = sqlite:///../../../langflow.db [post_write_hooks] diff --git a/src/backend/langflow/services/settings/base.py b/src/backend/langflow/services/settings/base.py index 1f30aa3e0..4e4ff164b 100644 --- a/src/backend/langflow/services/settings/base.py +++ b/src/backend/langflow/services/settings/base.py @@ -86,31 +86,29 @@ class Settings(BaseSettings): value = langflow_database_url logger.debug("Using LANGFLOW_DATABASE_URL env variable.") else: - # logger.debug("No DATABASE_URL env variable, using sqlite database") - logger.debug("No DATABASE_URL env variable, using custom database from secrets of {}".format(os.environ["host"])) + logger.debug("No DATABASE_URL env variable, using sqlite database") # Originally, we used sqlite:///./langflow.db # so we need to migrate to the new format # if there is a database in that location - # if not values["CONFIG_DIR"]: - # raise ValueError( - # "CONFIG_DIR not set, please set it or provide a DATABASE_URL" - # ) + if not values["CONFIG_DIR"]: + raise ValueError( + "CONFIG_DIR not set, please set it or provide a DATABASE_URL" + ) - # new_path = f"{values['CONFIG_DIR']}/langflow.db" - # if Path("./langflow.db").exists(): - # if Path(new_path).exists(): - # logger.debug(f"Database already exists at {new_path}, using it") - # else: - # try: - # logger.debug("Copying existing database to new location") - # copy2("./langflow.db", new_path) - # logger.debug(f"Copied existing database to {new_path}") - # except Exception: - # logger.error("Failed to copy database, using default path") - # new_path = "./langflow.db" + new_path = f"{values['CONFIG_DIR']}/langflow.db" + if Path("./langflow.db").exists(): + if Path(new_path).exists(): + logger.debug(f"Database already exists at {new_path}, using it") + else: + try: + logger.debug("Copying existing database to new location") + copy2("./langflow.db", new_path) + logger.debug(f"Copied existing database to {new_path}") + except Exception: + logger.error("Failed to copy database, using default path") + new_path = "./langflow.db" - # value = f"sqlite:///{new_path}" - value = "mysql+pymysql://{}:{}@{}:3306/{}".format(os.environ["username"],os.environ["password"],os.environ["host"],os.environ["dbname"]) + value = f"sqlite:///{new_path}" return value @@ -234,4 +232,4 @@ def load_settings_from_yaml(file_path: str) -> Settings: raise KeyError(f"Key {key} not found in settings") logger.debug(f"Loading {len(settings_dict[key])} {key} from {file_path}") - return Settings(**settings_dict) + return Settings(**settings_dict) \ No newline at end of file diff --git a/src/backend/langflow/settings.py b/src/backend/langflow/settings.py index ab9217d2c..1710bb013 100644 --- a/src/backend/langflow/settings.py +++ b/src/backend/langflow/settings.py @@ -46,10 +46,8 @@ class Settings(BaseSettings): value = langflow_database_url logger.debug("Using LANGFLOW_DATABASE_URL env variable.") else: - # logger.debug("No DATABASE_URL env variable, using sqlite database") - logger.debug("No DATABASE_URL env variable, using custom database from secrets of {}".format(os.environ["host"])) - # value = "sqlite:///./langflow.db" - value = "mysql+pymysql://{}:{}@{}:3306/{}".format(os.environ["username"],os.environ["password"],os.environ["host"],os.environ["dbname"]) + logger.debug("No DATABASE_URL env variable, using sqlite database") + value = "sqlite:///./langflow.db" return value @@ -176,4 +174,4 @@ def load_settings_from_yaml(file_path: str) -> Settings: return Settings(**settings_dict) -settings = load_settings_from_yaml("config.yaml") +settings = load_settings_from_yaml("config.yaml") \ No newline at end of file