From 7649902b67dd14234d163806913a48d91c3543c2 Mon Sep 17 00:00:00 2001 From: Edwin Eames Date: Wed, 28 Jan 2026 21:55:06 -0500 Subject: [PATCH] major claude changes --- config.py | 1 - main.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 12 ++++++++---- settings_local.py | 45 ++++++++++++++++++++++++--------------------- settings_prod.py | 38 ++++++++++++++++++++++---------------- 5 files changed, 100 insertions(+), 42 deletions(-) diff --git a/config.py b/config.py index df2e76a..590910b 100644 --- a/config.py +++ b/config.py @@ -3,7 +3,6 @@ import os def load_config(mode=os.environ.get('MODE')): try: - print(f"mode is {mode}") if mode == 'PRODUCTION': from settings_prod import ApplicationConfig return ApplicationConfig diff --git a/main.py b/main.py index 3b5075b..8d6e544 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,39 @@ +import logging +import sys from fastapi import FastAPI from app.routers import delivery from fastapi.middleware.cors import CORSMiddleware from config import load_config +from sqlalchemy import create_engine, text +from sqlalchemy.orm import sessionmaker ApplicationConfig = load_config() +# Configure logging +logging.basicConfig( + level=logging.INFO, + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + datefmt='%Y-%m-%d %H:%M:%S', + handlers=[logging.StreamHandler(sys.stdout)] +) +logger = logging.getLogger('eamco_money_api') + +# Database setup +engine = create_engine(ApplicationConfig.SQLALCHEMY_DATABASE_URI) +SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) + +def check_db_connection(): + """ + Test database connectivity. + """ + try: + db = SessionLocal() + db.execute(text("SELECT 1")) + db.close() + return True + except Exception: + return False app = FastAPI() @@ -23,3 +51,21 @@ app.add_middleware( @app.get("/") def read_root(): return {"Status": "Money Service is online"} + +@app.on_event("startup") +async def startup_event(): + """Application startup - log configuration and test DB connection.""" + logger.info("🚀 eamco_money_api STARTING") + mode = ApplicationConfig.CURRENT_SETTINGS.upper() + if mode in ['DEVELOPMENT', 'DEV']: + logger.info("🤖🤖🤖🤖🤖 Mode: Development 🤖🤖🤖🤖🤖") + elif mode in ['PRODUCTION', 'PROD']: + logger.info("💀💀💀💀💀💀💀💀💀💀 ⚠️ WARNING PRODUCTION 💀💀💀💀💀💀💀💀💀💀") + logger.info(f"DB: {ApplicationConfig.SQLALCHEMY_DATABASE_URI[:30]}...") + logger.info(f"CORS: {len(ApplicationConfig.origins)} origins configured") + + # Test database connection + if check_db_connection(): + logger.info("DB Connection: ✅ OK") + else: + logger.info("DB Connection: ❌ FAILED") diff --git a/requirements.txt b/requirements.txt index 4e961b3..175c5b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,8 @@ -fastapi -uvicorn[standard] -psycopg2-binary -sqlalchemy \ No newline at end of file +# eamco_money_api dependencies +# FastAPI web framework and server +fastapi==0.115.6 +uvicorn[standard]==0.34.0 + +# Database +SQLAlchemy==2.0.40 +psycopg2-binary==2.9.10 diff --git a/settings_local.py b/settings_local.py index 0076cd4..6303178 100644 --- a/settings_local.py +++ b/settings_local.py @@ -1,30 +1,33 @@ +import os class ApplicationConfig: """ - Basic Configuration for a generic User + Local Configuration (LAN deployment) """ CURRENT_SETTINGS = 'LOCAL' - # databases info - POSTGRES_USERNAME = 'postgres' - POSTGRES_PW = 'password' - POSTGRES_SERVER = '192.168.1.204' - POSTGRES_PORT = '5432' - POSTGRES_DBNAME00 = 'auburnoil' - SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(POSTGRES_USERNAME, - POSTGRES_PW, - POSTGRES_SERVER, - POSTGRES_DBNAME00 - ) + + # Database credentials from environment variables + POSTGRES_USERNAME = os.environ.get('POSTGRES_USERNAME', 'postgres') + POSTGRES_PW = os.environ.get('POSTGRES_PW') + POSTGRES_SERVER = os.environ.get('POSTGRES_SERVER', '192.168.1.204') + POSTGRES_PORT = os.environ.get('POSTGRES_PORT', '5432') + POSTGRES_DBNAME00 = os.environ.get('POSTGRES_DBNAME', 'auburnoil') + + SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format( + POSTGRES_USERNAME, + POSTGRES_PW, + POSTGRES_SERVER, + POSTGRES_DBNAME00 + ) SQLALCHEMY_BINDS = {'auburnoil': SQLALCHEMY_DATABASE_URI} - origins = [ - "http://192.168.1.204:9000", - "http://192.168.1.204:9613", - "http://192.168.1.204:9614", - "http://192.168.1.204:9612", - "http://192.168.1.204:9616", - "http://192.168.1.204:9611", - "http://192.168.1.204:9511", -] \ No newline at end of file + "http://192.168.1.204:9000", + "http://192.168.1.204:9613", + "http://192.168.1.204:9614", + "http://192.168.1.204:9612", + "http://192.168.1.204:9616", + "http://192.168.1.204:9611", + "http://192.168.1.204:9511", + ] diff --git a/settings_prod.py b/settings_prod.py index fcda382..ace6192 100644 --- a/settings_prod.py +++ b/settings_prod.py @@ -1,22 +1,28 @@ +import os + + class ApplicationConfig: """ - Basic Configuration for a generic User + Production Configuration """ CURRENT_SETTINGS = 'PRODUCTION' - # databases info - POSTGRES_USERNAME = 'postgres' - POSTGRES_PW = 'password' - POSTGRES_SERVER = '192.168.1.204' - POSTGRES_PORT = '5432' - POSTGRES_DBNAME00 = 'auburnoil' - SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(POSTGRES_USERNAME, - POSTGRES_PW, - POSTGRES_SERVER, - POSTGRES_DBNAME00 - ) + + # Database credentials from environment variables + POSTGRES_USERNAME = os.environ.get('POSTGRES_USERNAME', 'postgres') + POSTGRES_PW = os.environ.get('POSTGRES_PW') + POSTGRES_SERVER = os.environ.get('POSTGRES_SERVER', '192.168.1.204') + POSTGRES_PORT = os.environ.get('POSTGRES_PORT', '5432') + POSTGRES_DBNAME00 = os.environ.get('POSTGRES_DBNAME', 'auburnoil') + + SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format( + POSTGRES_USERNAME, + POSTGRES_PW, + POSTGRES_SERVER, + POSTGRES_DBNAME00 + ) SQLALCHEMY_BINDS = {'auburnoil': SQLALCHEMY_DATABASE_URI} - + origins = [ - "https://oil.edwineames.com", - "https://apiauto.edwineames.com", -] \ No newline at end of file + "https://oil.edwineames.com", + "https://apiauto.edwineames.com", + ]