db.py 575 Bytes
Newer Older
Timothy J. Baek's avatar
Timothy J. Baek committed
1
from peewee import *
2
from peewee_migrate import Router
3
from config import SRC_LOG_LEVELS, DATA_DIR
4
import os
5
import logging
Timothy J. Baek's avatar
Timothy J. Baek committed
6

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

10
11
12
13
# 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")
14
    log.info("File renamed successfully.")
15
16
17
18
19
else:
    pass


DB = SqliteDatabase(f"{DATA_DIR}/webui.db")
20
21
22
router = Router(DB, migrate_dir="apps/web/internal/migrations", logger=log)
router.run()
DB.connect(reuse_if_open=True)