From 76cb49e908932d45af51699f71beb60a516c14fe Mon Sep 17 00:00:00 2001 From: Marko Djordjevic Date: Fri, 20 Feb 2026 21:34:31 +0100 Subject: [PATCH] Migrate MLflow backend to PostgreSQL and fix .env loading - Add python-dotenv loading in main.py so DATABASE_URL is read from .env before db.py module initializes - Add MLFLOW_TRACKING_URI to .env.example pointing to PostgreSQL - Add python-dotenv>=1.0.0 to pyproject.toml dependencies - Initialize MLflow schema in candle_annotator PostgreSQL database MLflow server now starts without filesystem deprecation warnings and with full job execution support. Co-Authored-By: Claude Sonnet 4.6 --- services/ml/.env.example | 1 + services/ml/app/main.py | 4 ++++ services/ml/pyproject.toml | 1 + 3 files changed, 6 insertions(+) diff --git a/services/ml/.env.example b/services/ml/.env.example index 2ebce8a..965d4d6 100644 --- a/services/ml/.env.example +++ b/services/ml/.env.example @@ -1,3 +1,4 @@ DATABASE_URL=postgresql://pg_user:pg_password@localhost:5432/candle_annotator +MLFLOW_TRACKING_URI=postgresql://pg_user:pg_password@localhost:5432/candle_annotator # openssl rand -hex 32 add to main .env too API_KEY=ML_API_KEY diff --git a/services/ml/app/main.py b/services/ml/app/main.py index 730c70c..6293671 100644 --- a/services/ml/app/main.py +++ b/services/ml/app/main.py @@ -17,6 +17,10 @@ from typing import Optional, Dict, Any, List from datetime import datetime, timezone import json +# Load .env file before any module that reads environment variables +from dotenv import load_dotenv +load_dotenv(Path(__file__).parent.parent / ".env") + import requests as http_requests from fastapi import FastAPI, HTTPException, Header, Depends, Security, status, Response diff --git a/services/ml/pyproject.toml b/services/ml/pyproject.toml index f56f6be..a7c873f 100644 --- a/services/ml/pyproject.toml +++ b/services/ml/pyproject.toml @@ -19,6 +19,7 @@ dependencies = [ "psycopg2-binary>=2.9.9", "pydantic>=2.5.0", "pydantic-settings>=2.1.0", + "python-dotenv>=1.0.0", "matplotlib>=3.8.2", "seaborn>=0.13.1", ]