Files
papi-py/db.py
stephen schuresko e59924b1fe
Some checks failed
Build and Push to Private Registry101 / build (push) Failing after 6s
Build and Push to Private Registry101 / deploy (push) Has been skipped
feat: enhance deployment and installation process in build-and-push workflow
2025-03-07 14:13:09 -05:00

25 lines
664 B
Python

from sqlalchemy import create_engine, Column, Integer,String, ForeignKey
from sqlalchemy.engine import URL
from sqlalchemy.orm import sessionmaker, Session, declarative_base
import os
# Database setup
DATABASE_URL = "sqlite:///./test.db"
if os.getenv("DATABASE_URL"):
DATABASE_URL = os.getenv("DATABASE_URL")
engine = create_engine(DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
version = os.environ.get("VERSION", "0.0.0")
def create_db():
Base.metadata.create_all(bind=engine)
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()