diff --git a/src/backend/base/langflow/__main__.py b/src/backend/base/langflow/__main__.py index 4e09b8ee5..726b967a5 100644 --- a/src/backend/base/langflow/__main__.py +++ b/src/backend/base/langflow/__main__.py @@ -2,9 +2,9 @@ import platform import socket import sys import time +import warnings from pathlib import Path from typing import Optional -import warnings import click import httpx @@ -443,6 +443,41 @@ def superuser( typer.echo("Superuser creation failed.") +# command to copy the langflow database from the cache to the current directory +# because now the database is stored per installation +@app.command() +def copy_db(): + """ + Copy the database files to the current directory. + + This function copies the 'langflow.db' and 'langflow-pre.db' files from the cache directory to the current directory. + If the files exist in the cache directory, they will be copied to the same directory as this script (__main__.py). + + Returns: + None + """ + import shutil + + from platformdirs import user_cache_dir + + cache_dir = Path(user_cache_dir("langflow")) + db_path = cache_dir / "langflow.db" + pre_db_path = cache_dir / "langflow-pre.db" + # It should be copied to the current directory + # this file is __main__.py and it should be in the same directory as the database + destination_folder = Path(__file__).parent + if db_path.exists(): + shutil.copy(db_path, destination_folder) + typer.echo(f"Database copied to {destination_folder}") + else: + typer.echo("Database not found in the cache directory.") + if pre_db_path.exists(): + shutil.copy(pre_db_path, destination_folder) + typer.echo(f"Pre-release database copied to {destination_folder}") + else: + typer.echo("Pre-release database not found in the cache directory.") + + @app.command() def migration( test: bool = typer.Option(True, help="Run migrations in test mode."),