-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
30 lines (26 loc) · 940 Bytes
/
config.py
File metadata and controls
30 lines (26 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from motor.motor_asyncio import AsyncIOMotorClient
from beanie import init_beanie
import os
from dotenv import load_dotenv
from models import UserProgress
import logging
load_dotenv()
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('devquest.log'),
logging.StreamHandler()
]
)
async def init_db():
logger = logging.getLogger('devquest.database')
try:
client = AsyncIOMotorClient(os.getenv("MONGODB_URI", "mongodb://localhost:27017"))
db = client[os.getenv("DB_NAME")]
logger.info(f"Connecting to MongoDB database: {os.getenv('DB_NAME')}")
await init_beanie(database=db, document_models=[UserProgress])
logger.info("Successfully initialized Beanie with MongoDB")
except Exception as e:
logger.error(f"Failed to initialize database: {str(e)}")
raise