- api/: FastAPI app with MySQL (accounts, forwarding_rules, messages)
- GET/POST/PUT/DELETE /accounts + /accounts/{id}/test
- GET /messages + /messages/{id}/retry
- GET /stats
- POST /connection/test
- Auto-runs migrations/init.sql on startup
- worker/: Python IMAP poller + BizDocs upload (schedule every 5 min)
- web/: multi-stage Dockerfile — builds admin-ui via Node, serves via nginx
- nginx proxies /api/ → api:8000, SPA fallback for React Router
- docker-compose.yml: updated web build context + mysql init.sql mount
Co-Authored-By: Paperclip <[email protected]>
33 lines
989 B
Python
33 lines
989 B
Python
from sqlalchemy import create_engine, text
|
|
from sqlalchemy.orm import sessionmaker, declarative_base
|
|
from .config import settings
|
|
|
|
DATABASE_URL = (
|
|
f"mysql+pymysql://{settings.mysql_user}:{settings.mysql_password}"
|
|
f"@{settings.mysql_host}:{settings.mysql_port}/{settings.mysql_database}"
|
|
"?charset=utf8mb4"
|
|
)
|
|
|
|
engine = create_engine(DATABASE_URL, pool_pre_ping=True, pool_recycle=3600)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
Base = declarative_base()
|
|
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
def run_migrations():
|
|
"""Apply init.sql on startup if tables are absent."""
|
|
import pathlib
|
|
sql_file = pathlib.Path(__file__).parent.parent / "migrations" / "init.sql"
|
|
statements = [s.strip() for s in sql_file.read_text().split(";") if s.strip()]
|
|
with engine.connect() as conn:
|
|
for stmt in statements:
|
|
conn.execute(text(stmt))
|
|
conn.commit()
|