Spaces:
Sleeping
Sleeping
File size: 976 Bytes
23d1df7 09ecaf7 23d1df7 09ecaf7 23d1df7 09ecaf7 23d1df7 09ecaf7 23d1df7 09ecaf7 23d1df7 |
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 28 29 30 31 32 33 34 35 36 |
# app/database.py
import os
import logging
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, declarative_base
from .config import settings
# 1) Grab the raw DATABASE_URL (e.g. "postgresql://...:5433/promptaid?schema=public")
raw_db_url = settings.DATABASE_URL
logging.getLogger().warning(f"▶️ Raw DATABASE_URL = {raw_db_url!r}")
# 2) Strip off any query string (everything from the first "?" onward)
clean_db_url = raw_db_url.split("?", 1)[0]
logging.getLogger().warning(f"▶️ Using clean URL = {clean_db_url!r}")
# 3) Create the SQLAlchemy engine on that clean URL
engine = create_engine(
clean_db_url,
echo=True, # log all SQL to the console
future=True # recommended for SQLAlchemy 2.0 style
)
# 4) Configure a session factory
SessionLocal = sessionmaker(
autocommit=False,
autoflush=False,
bind=engine,
future=True
)
# 5) Base class for all ORM models
Base = declarative_base()
|