Unify parsing workers, analytics API with PostgreSQL, map UI, and PI distribution into centers/ with Docker Compose. Co-authored-by: Cursor <cursoragent@cursor.com>
29 lines
596 B
Python
29 lines
596 B
Python
import os
|
|
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import DeclarativeBase, sessionmaker
|
|
|
|
DATABASE_URL = os.getenv(
|
|
"DATABASE_URL",
|
|
"postgresql://mapmil:mapmil@ca-db:5432/mapmil",
|
|
)
|
|
|
|
connect_args: dict = {}
|
|
if DATABASE_URL.startswith("sqlite"):
|
|
connect_args = {"check_same_thread": False}
|
|
|
|
engine = create_engine(DATABASE_URL, connect_args=connect_args)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|