Update project files
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -20,3 +20,14 @@ def get_db():
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def switch_database(db_path: Path):
|
||||
"""Hot-swap the active database engine and session factory."""
|
||||
global engine, SessionLocal, DB_PATH
|
||||
DB_PATH = db_path
|
||||
engine.dispose()
|
||||
engine = create_engine(f"sqlite:///{db_path}", echo=False)
|
||||
SessionLocal = sessionmaker(bind=engine, class_=Session, expire_on_commit=False)
|
||||
Base.metadata.create_all(bind=engine)
|
||||
return engine
|
||||
|
||||
Reference in New Issue
Block a user