modify: set_database_url
This commit is contained in:
parent
ca723d6ce9
commit
90759feb2f
3 changed files with 31 additions and 27 deletions
|
|
@ -127,13 +127,13 @@ def run(
|
|||
default=None,
|
||||
),
|
||||
dev: bool = typer.Option(False, help="Run in development mode (may contain bugs)"),
|
||||
# This variable does not work but is set by the .env file
|
||||
# and works with Pydantic
|
||||
database_url: str = typer.Option(
|
||||
"mysql+pymysql://{}:{}@{}:3306/{}".format(os.environ["username"],os.environ["password"],os.environ["host"],os.environ["dbname"]),
|
||||
help="Database URL to connect to. If not provided, a local SQLite database will be used.",
|
||||
envvar="LANGFLOW_DATABASE_URL",
|
||||
),
|
||||
# # This variable does not work but is set by the .env file
|
||||
# # and works with Pydantic
|
||||
# database_url: str = typer.Option(
|
||||
# "mysql+pymysql://{}:{}@{}:3306/{}".format(os.environ["username"],os.environ["password"],os.environ["host"],os.environ["dbname"]),
|
||||
# help="Database URL to connect to. If not provided, a local SQLite database will be used.",
|
||||
# envvar="LANGFLOW_DATABASE_URL",
|
||||
# ),
|
||||
path: str = typer.Option(
|
||||
None,
|
||||
help="Path to the frontend directory containing build files. This is for development purposes only.",
|
||||
|
|
|
|||
|
|
@ -86,29 +86,31 @@ 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 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
|
||||
# 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 = f"sqlite:///{new_path}"
|
||||
value = "mysql+pymysql://{}:{}@{}:3306/{}".format(os.environ["username"],os.environ["password"],os.environ["host"],os.environ["dbname"])
|
||||
|
||||
return value
|
||||
|
||||
|
|
|
|||
|
|
@ -46,8 +46,10 @@ 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")
|
||||
value = "sqlite:///./langflow.db"
|
||||
# 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"])
|
||||
|
||||
return value
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue