Refactor OpenAPI fetcher for improved clarity and robustness

Reorganized and enhanced the OpenAPI fetch logic for better maintainability and error handling. Key updates include improved environment variable validation, more detailed error messages, streamlined configuration loading, and additional safety checks for file paths and directories. Added proper logging and ensured the process flow is easy to trace.
This commit is contained in:
GotthardG
2024-12-17 16:25:53 +01:00
parent dbf7864e7e
commit 9b6ad107bb
2 changed files with 25 additions and 9 deletions

View File

@ -48,10 +48,19 @@ def load_slots_data(session: Session):
from .data import slots
from .data import proposals
if not session.query(models.Slot).first(): # Load only if no slots exist
session.add_all(slots)
session.add_all(proposals)
session.commit()
# Only load data if slots are missing
if not session.query(models.Slot).first():
session.add_all(slots) # Add slots
print("[INFO] Seeding slots...")
# Check if proposals table is empty and seed proposals
if not session.query(models.Proposal).first():
session.add_all(proposals) # Add proposals
print("[INFO] Seeding proposals...")
# Commit all changes to the database
session.commit()
print("[INFO] Seeding complete.")
# Load full sample data (used in dev/test)