Files
pragativeer-v2/backend/database.py

19 lines
753 B
Python

import os
from sqlmodel import create_engine, SQLModel, Session
from typing import Generator
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://pragativeer_admin:local_secure_password_2026@postgres:5432/pragativeer_prod")
connect_args = {"options": "-c timezone=Asia/Kolkata"} if "postgresql" in DATABASE_URL else {}
# Using the standard SQLModel engine config for PostgreSQL with IST timezone session
engine = create_engine(DATABASE_URL, echo=True, connect_args=connect_args)
def init_db():
# Automatically generates tables based on the classes imported from models.py
import models
SQLModel.metadata.create_all(engine)
def get_session() -> Generator[Session, None, None]:
with Session(engine) as session:
yield session