admin / Synapse-Cortex
publicSelf Hosted ITSM Tool with RBAC/Tenanting and MFA
Synapse-Cortex / Synapse-Cortexv2 / app / database.py
699 B · main
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import os from dotenv import load_dotenv from sqlalchemy import create_engine from sqlalchemy.orm import declarative_base, sessionmaker # Never overrides real environment variables (e.g. the ones docker-compose # sets) - this only fills in DATABASE_URL/SECRET_KEY for local dev when # they're otherwise unset. load_dotenv() DATABASE_URL = os.getenv( "DATABASE_URL", "postgresql+psycopg2://cortex:cortex@db:5432/synapse_cortex", ) engine = create_engine(DATABASE_URL, pool_pre_ping=True) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) Base = declarative_base() def get_db(): db = SessionLocal() try: yield db finally: db.close() |