18 lines
605 B
Python
18 lines
605 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")
|
|
|
|
# Using the standard SQLModel engine config for PostgreSQL
|
|
engine = create_engine(DATABASE_URL, echo=True)
|
|
|
|
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
|