Spaces:
Sleeping
Sleeping
MD.Riad Rayhan commited on
Remove provisioning/device-owner endpoints; Device Admin only
Browse files1 unmodified line234567891011 unmodified lines222324252627281 unmodified linefrom sqlalchemy.ext.declarative import declarative_basefrom sqlalchemy.orm import sessionmakerimport osfrom app.core.config import settings# Handle different database URL formatsdb_url = settings.DATABASE_URLif db_url.startswith("postgres://"):11 unmodified linesdb_url = f"sqlite:///{persistent_dir}/emi_locker.db"engine = create_engine(db_url, connect_args={"check_same_thread": False})else:# Postgres / MySQL: pool_pre_ping avoids stale-connection errors on managed DBs.engine = create_engine(db_url, pool_pre_ping=True, pool_recycle=300)1 unmodified line234567891011121314151617181920212223242526272829303111 unmodified lines4344454647484950511 unmodified linefrom sqlalchemy.ext.declarative import declarative_basefrom sqlalchemy.orm import sessionmakerimport osimport refrom urllib.parse import quotefrom app.core.config import settingsdef _sanitize_db_url(url: str) -> str:"""Percent-encode the username/password in a SQL connection URL so thatspecial characters (@ : / # ? etc.) in a Supabase/Neon password don't breakURL parsing and crash the app at import time."""m = re.match(r"^(?P<scheme>[^:]+)://(?P<body>.+)$", url)if not m or "@" not in m.group("body"):return urlbody = m.group("body")# Split on the LAST '@' so a password containing '@' is handled correctly.userinfo, host = body.rsplit("@", 1)if ":" not in userinfo:return urluser, password = userinfo.split(":", 1)safe_user = quote(user, safe="")safe_password = quote(password, safe="")return f"{m.group('scheme')}://{safe_user}:{safe_password}@{host}"# Handle different database URL formatsdb_url = settings.DATABASE_URLif db_url.startswith("postgres://"):11 unmodified linesdb_url = f"sqlite:///{persistent_dir}/emi_locker.db"engine = create_engine(db_url, connect_args={"check_same_thread": False})else:# Postgres / MySQL: encode credentials, then build the engine.# pool_pre_ping avoids stale-connection errors on managed DBs (Supabase pooler).db_url = _sanitize_db_url(db_url)engine = create_engine(db_url, pool_pre_ping=True, pool_recycle=300)
app/core/database.py+24-1