From d17ff9cae9ca6e3b918c7bcc91bd08cbd410ab5e Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 25 Sep 2020 16:07:44 -0500 Subject: [PATCH] Add support for multiple DB engines, for Catapult views --- theo/web/app.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/theo/web/app.py b/theo/web/app.py index 076fbdf..b9180ee 100644 --- a/theo/web/app.py +++ b/theo/web/app.py @@ -24,6 +24,9 @@ Theo web app """ +from sqlalchemy.orm import sessionmaker, scoped_session +from zope.sqlalchemy import register + from tailbone import app from theo.config import integrate_catapult, integrate_corepos, integrate_locsms @@ -53,13 +56,26 @@ def main(global_config, **settings): # establish pyramid config pyramid_config = app.make_pyramid_config(settings) - # maybe configure integration db connections - if integrate_catapult(rattail_config): - from tailbone_onager.db import CatapultSession - CatapultSession.configure(bind=rattail_config.catapult_engine) + # CORE-POS DB(s) if integrate_corepos(rattail_config): from tailbone_corepos.db import CoreOfficeSession CoreOfficeSession.configure(bind=rattail_config.corepos_engine) + + # Catapult DB(s) + if integrate_catapult(rattail_config): + from tailbone_onager.db import CatapultSession, ExtraCatapultSessions + + # default session / engine + CatapultSession.configure(bind=rattail_config.catapult_engine) + + # make session wrappers for each "extra" engine + for key, engine in rattail_config.catapult_engines.items(): + if key != 'default': + Session = scoped_session(sessionmaker(bind=engine)) + register(Session) + ExtraCatapultSessions[key] = Session + + # LOC SMS DB(s) if integrate_locsms(rattail_config): from tailbone_locsms.db import SmsSession SmsSession.configure(bind=rattail_config.locsms_engine)