feat: migrate backend persistence from TinyDB to MongoDB Atlas
- Implement lazy MongoDB client initialization in backend/db/mongo_client.py. - Create Gunicorn configuration to ensure MongoDB client is initialized per worker. - Refactor database access layer to support MongoDB with a new MongoLockedTable adapter. - Add migration script to transfer existing TinyDB data to MongoDB, preserving idempotency. - Update tracking event handling to ensure deterministic ordering with a monotonic sequence. - Modify tests to use mongomock for MongoDB integration and ensure existing tests pass. - Add integration test script to run tests against a local MongoDB Docker container. - Document environment variables and migration process in specs/feat-database-migration.md.
This commit is contained in:
+5
-1
@@ -4,7 +4,6 @@ import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from flask import Flask, request, jsonify
|
||||
from pymongo import MongoClient
|
||||
|
||||
from api.admin_api import admin_api
|
||||
from api.auth_api import auth_api
|
||||
@@ -28,6 +27,7 @@ from api.digest_action_api import digest_action_api
|
||||
from config.version import get_full_version
|
||||
|
||||
from db.default import initializeImages, createDefaultTasks, createDefaultRewards
|
||||
from db.db import ensure_mongodb_indexes
|
||||
from events.broadcaster import Broadcaster
|
||||
from events.sse import sse_response_for_user, send_to_user
|
||||
from api.utils import get_current_user_id
|
||||
@@ -39,6 +39,10 @@ from utils.state_expiry_scheduler import start_state_expiry_scheduler
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
|
||||
# Ensure MongoDB indexes exist when running against MongoDB.
|
||||
ensure_mongodb_indexes()
|
||||
|
||||
# Configure logging once at application startup
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
|
||||
Reference in New Issue
Block a user