Fix MTGJSON download functionality
- Add refresh router with admin-only endpoints - Fix _decompress_file to handle .psql files correctly - Fix duplicate imports in mtgjson_manager.py - Mount refresh router in main.py - Add download_mtgjson.py standalone script - Add SUPPORTED_FILE_TYPES.md documentation
This commit is contained in:
+11
-12
@@ -24,7 +24,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.core.settings import get_settings
|
||||
from app.core.database import engine, mtg_engine, async_session, mtg_async_session
|
||||
from app.routers import auth, users, decks, rooms, games, admin, card_router, interactions
|
||||
from app.routers import auth, users, decks, rooms, games, admin, card_router, interactions, refresh
|
||||
from app.services.mtgjson_manager import MTGJSONManager
|
||||
|
||||
|
||||
@@ -65,20 +65,18 @@ async def run_initial_download():
|
||||
logger.info("Running initial MTGJSON data download with sanity checks...")
|
||||
logger.info("This may take several minutes depending on network speed...")
|
||||
|
||||
# Download files with sanity checking and retry logic
|
||||
success = await manager.download_with_sanity_check()
|
||||
if not success:
|
||||
logger.error("Failed to download MTGJSON files after retries - marking container unhealthy")
|
||||
raise RuntimeError("MTGJSON data download failed after all retry attempts")
|
||||
# Download files and upsert data in one operation
|
||||
result = await manager.download_and_refresh(force=False)
|
||||
|
||||
# Unpack files
|
||||
await manager.unpack_files()
|
||||
|
||||
# Upsert data
|
||||
counts = await manager.upsert_data()
|
||||
if not result.get("success", False):
|
||||
error_msg = result.get("error", "Unknown error")
|
||||
logger.error(f"Failed to download MTGJSON files: {error_msg}")
|
||||
raise RuntimeError(f"MTGJSON data download failed: {error_msg}")
|
||||
|
||||
# Log success
|
||||
await manager.log_refresh("SUCCESS", counts, 0)
|
||||
counts = result.get("upsert", {})
|
||||
await manager.log_refresh("SUCCESS", counts, result.get("duration", 0))
|
||||
|
||||
logger.info(f"Initial MTGJSON data load complete!")
|
||||
logger.info(f" Sets: {counts.get('sets', 0)}")
|
||||
logger.info(f" Cards: {counts.get('cards', 0)}")
|
||||
@@ -141,6 +139,7 @@ app.include_router(games.router, prefix="/games", tags=["Games"])
|
||||
app.include_router(admin.router, prefix="/admin", tags=["Admin"])
|
||||
app.include_router(card_router.router, prefix="/api", tags=["MTG Cards"])
|
||||
app.include_router(interactions.router, tags=["Card Interactions"])
|
||||
app.include_router(refresh.router)
|
||||
|
||||
|
||||
@app.get("/health", tags=["Health"])
|
||||
|
||||
Reference in New Issue
Block a user