1010from dataclasses import dataclass , asdict
1111from typing import Dict , Any
1212
13- from sqlalchemy .pool import QueuePool
13+ from sqlalchemy .pool import QueuePool , NullPool
1414from sqlalchemy .exc import IntegrityError
1515from sqlalchemy .ext .declarative import declarative_base
1616from sqlalchemy .orm import Session , scoped_session , sessionmaker , relationship
5555 )
5656else :
5757 logger .info (f"Using via database URL" )
58+ # https://stackoverflow.com/a/73764136
59+ #
5860 engine = create_engine (
5961 db ,
6062 poolclass = QueuePool ,
@@ -84,7 +86,7 @@ def get_random_number(length) -> int:
8486 return random_numbers
8587
8688
87- def get_local_session () -> sessionmaker :
89+ def get_local_session (engine ) -> sessionmaker :
8890 logger .debug ("Database opened successfully" )
8991 SessionLocal = sessionmaker (autocommit = False , autoflush = False , bind = engine )
9092 return SessionLocal
@@ -101,7 +103,7 @@ def db_session() -> Session: # type: ignore
101103
102104
103105def fastapi_db_session ():
104- sess_cls = get_local_session ()
106+ sess_cls = get_local_session (engine )
105107 db = sess_cls ()
106108 try :
107109 yield db
@@ -272,7 +274,7 @@ class Prompt(Base):
272274 meta : Dict [str , Any ] = Column (JSON )
273275
274276 # migrate to snowflake ID
275- sf_id = Column (String (19 ), nullable = True )
277+ # sf_id = Column(String(19), nullable=True)
276278
277279 def to_dict (self ):
278280 return {
@@ -303,7 +305,7 @@ class ChainLog(Base):
303305 )
304306 created_at : datetime = Column (DateTime , nullable = False )
305307 prompt_id : int = Column (Integer , ForeignKey ("prompt.id" ), nullable = False )
306- node_id : str = Column (String (Env .CFS_MAXLEN_CF_NDOE ()), nullable = False )
308+ node_id : str = Column (String (Env .CFS_MAXLEN_CF_NODE ()), nullable = False )
307309 worker_id : str = Column (String (Env .CFS_MAXLEN_WORKER ()), nullable = False )
308310 message : str = Column (Text , nullable = False )
309311 data : Dict [str , Any ] = Column (JSON , nullable = True )
0 commit comments