"src/lib/components/admin/Settings/Documents.svelte" did not exist on "099b1d066bd593b3119fb7b0e850627b95548711"
db.py 738 Bytes
Newer Older
Timothy J. Baek's avatar
Timothy J. Baek committed
1
from peewee import *
2
from peewee_migrate import Router
3
from playhouse.db_url import connect
Tang Ziya's avatar
Tang Ziya committed
4
from config import SRC_LOG_LEVELS, DATA_DIR, DATABASE_URL, BACKEND_DIR
5
import os
6
import logging
Timothy J. Baek's avatar
Timothy J. Baek committed
7

8
9
log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["DB"])
10

11
12
13
14
# Check if the file exists
if os.path.exists(f"{DATA_DIR}/ollama.db"):
    # Rename the file
    os.rename(f"{DATA_DIR}/ollama.db", f"{DATA_DIR}/webui.db")
15
    log.info("Database migrated from Ollama-WebUI successfully.")
16
17
18
else:
    pass

19
20
DB = connect(DATABASE_URL)
log.info(f"Connected to a {DB.__class__.__name__} database.")
Tang Ziya's avatar
Tang Ziya committed
21
22
23
router = Router(
    DB, migrate_dir=BACKEND_DIR / "apps" / "web" / "internal" / "migrations", logger=log
)
24
25
router.run()
DB.connect(reuse_if_open=True)