Add support for multiple DB engines, for Catapult views

This commit is contained in:
Lance Edgar 2020-09-25 16:07:44 -05:00
parent ed6e4f0e5b
commit d17ff9cae9

View file

@ -24,6 +24,9 @@
Theo web app Theo web app
""" """
from sqlalchemy.orm import sessionmaker, scoped_session
from zope.sqlalchemy import register
from tailbone import app from tailbone import app
from theo.config import integrate_catapult, integrate_corepos, integrate_locsms from theo.config import integrate_catapult, integrate_corepos, integrate_locsms
@ -53,13 +56,26 @@ def main(global_config, **settings):
# establish pyramid config # establish pyramid config
pyramid_config = app.make_pyramid_config(settings) pyramid_config = app.make_pyramid_config(settings)
# maybe configure integration db connections # CORE-POS DB(s)
if integrate_catapult(rattail_config):
from tailbone_onager.db import CatapultSession
CatapultSession.configure(bind=rattail_config.catapult_engine)
if integrate_corepos(rattail_config): if integrate_corepos(rattail_config):
from tailbone_corepos.db import CoreOfficeSession from tailbone_corepos.db import CoreOfficeSession
CoreOfficeSession.configure(bind=rattail_config.corepos_engine) 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): if integrate_locsms(rattail_config):
from tailbone_locsms.db import SmsSession from tailbone_locsms.db import SmsSession
SmsSession.configure(bind=rattail_config.locsms_engine) SmsSession.configure(bind=rattail_config.locsms_engine)