refactor: Copy langflow database from cache to current directory
This commit is contained in:
parent
cecbd724e5
commit
8a70c655cc
1 changed files with 36 additions and 1 deletions
|
|
@ -2,9 +2,9 @@ import platform
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import warnings
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import warnings
|
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import httpx
|
import httpx
|
||||||
|
|
@ -443,6 +443,41 @@ def superuser(
|
||||||
typer.echo("Superuser creation failed.")
|
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()
|
@app.command()
|
||||||
def migration(
|
def migration(
|
||||||
test: bool = typer.Option(True, help="Run migrations in test mode."),
|
test: bool = typer.Option(True, help="Run migrations in test mode."),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue