Refactor database connection logic in base
settings
This commit is contained in:
parent
79c93bcfe9
commit
501ba416d1
1 changed files with 22 additions and 24 deletions
|
|
@ -1,15 +1,15 @@
|
||||||
import contextlib
|
import contextlib
|
||||||
import json
|
import json
|
||||||
import orjson
|
|
||||||
import os
|
import os
|
||||||
from shutil import copy2
|
|
||||||
from typing import Optional, List
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from shutil import copy2
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
import orjson
|
||||||
import yaml
|
import yaml
|
||||||
|
from loguru import logger
|
||||||
from pydantic import field_validator, validator
|
from pydantic import field_validator, validator
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
from loguru import logger
|
|
||||||
|
|
||||||
# BASE_COMPONENTS_PATH = str(Path(__file__).parent / "components")
|
# BASE_COMPONENTS_PATH = str(Path(__file__).parent / "components")
|
||||||
BASE_COMPONENTS_PATH = str(Path(__file__).parent.parent.parent / "components")
|
BASE_COMPONENTS_PATH = str(Path(__file__).parent.parent.parent / "components")
|
||||||
|
|
@ -86,31 +86,29 @@ class Settings(BaseSettings):
|
||||||
value = langflow_database_url
|
value = langflow_database_url
|
||||||
logger.debug("Using LANGFLOW_DATABASE_URL env variable.")
|
logger.debug("Using LANGFLOW_DATABASE_URL env variable.")
|
||||||
else:
|
else:
|
||||||
# logger.debug("No DATABASE_URL env variable, using sqlite database")
|
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"]))
|
|
||||||
# Originally, we used sqlite:///./langflow.db
|
# Originally, we used sqlite:///./langflow.db
|
||||||
# so we need to migrate to the new format
|
# so we need to migrate to the new format
|
||||||
# if there is a database in that location
|
# if there is a database in that location
|
||||||
# if not values["CONFIG_DIR"]:
|
if not values["CONFIG_DIR"]:
|
||||||
# raise ValueError(
|
raise ValueError(
|
||||||
# "CONFIG_DIR not set, please set it or provide a DATABASE_URL"
|
"CONFIG_DIR not set, please set it or provide a DATABASE_URL"
|
||||||
# )
|
)
|
||||||
|
|
||||||
# new_path = f"{values['CONFIG_DIR']}/langflow.db"
|
new_path = f"{values['CONFIG_DIR']}/langflow.db"
|
||||||
# if Path("./langflow.db").exists():
|
if Path("./langflow.db").exists():
|
||||||
# if Path(new_path).exists():
|
if Path(new_path).exists():
|
||||||
# logger.debug(f"Database already exists at {new_path}, using it")
|
logger.debug(f"Database already exists at {new_path}, using it")
|
||||||
# else:
|
else:
|
||||||
# try:
|
try:
|
||||||
# logger.debug("Copying existing database to new location")
|
logger.debug("Copying existing database to new location")
|
||||||
# copy2("./langflow.db", new_path)
|
copy2("./langflow.db", new_path)
|
||||||
# logger.debug(f"Copied existing database to {new_path}")
|
logger.debug(f"Copied existing database to {new_path}")
|
||||||
# except Exception:
|
except Exception:
|
||||||
# logger.error("Failed to copy database, using default path")
|
logger.error("Failed to copy database, using default path")
|
||||||
# new_path = "./langflow.db"
|
new_path = "./langflow.db"
|
||||||
|
|
||||||
# value = f"sqlite:///{new_path}"
|
value = f"sqlite:///{new_path}"
|
||||||
value = "mysql+pymysql://{}:{}@{}:3306/{}".format(os.environ["username"],os.environ["password"],os.environ["host"],os.environ["dbname"])
|
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue