feat: add support for lane_op
and lane_trans
DB sessions, models
This commit is contained in:
parent
bf6bf63e68
commit
e6921c8533
6 changed files with 158 additions and 2 deletions
|
@ -74,6 +74,34 @@ class WuttaCoreposConfigExtension(WuttaConfigExtension):
|
|||
Dict of ``office_arch`` DB engines. May be empty if no config
|
||||
is found; otherwise there should at least be a ``default`` key
|
||||
defined, corresonding to :data:`core_office_arch_engine`.
|
||||
|
||||
.. data:: core_lane_op_engine
|
||||
|
||||
Primary engine for the ``lane_op`` DB. May be null if no
|
||||
"default" engine is configured - which is *typical* for a
|
||||
multi-lane environment. See :data:`core_lane_op_engines` for
|
||||
the full set.
|
||||
|
||||
.. data:: core_lane_op_engines
|
||||
|
||||
Dict of ``lane_op`` DB engines. May be empty if no config is
|
||||
found; otherwise keys are typically like ``01`` and ``02`` etc.
|
||||
If present, the ``default`` key will correspond to
|
||||
:data:`core_lane_op_engine`.
|
||||
|
||||
.. data:: core_lane_trans_engine
|
||||
|
||||
Primary engine for the ``lane_trans`` DB. May be null if no
|
||||
"default" engine is configured - which is *typical* for a
|
||||
multi-lane environment. See :data:`core_lane_trans_engines`
|
||||
for the full set.
|
||||
|
||||
.. data:: core_lane_trans_engines
|
||||
|
||||
Dict of ``lane_trans`` DB engines. May be empty if no config
|
||||
is found; otherwise keys are typically like ``01`` and ``02``
|
||||
etc. If present, the ``default`` key will correspond to
|
||||
:data:`core_lane_trans_engine`.
|
||||
"""
|
||||
key = 'wutta_corepos'
|
||||
|
||||
|
@ -101,6 +129,20 @@ class WuttaCoreposConfigExtension(WuttaConfigExtension):
|
|||
config.core_office_arch_engine = engines.get('default')
|
||||
Session.configure(bind=config.core_office_arch_engine)
|
||||
|
||||
# lane_op
|
||||
from corepos.db.lane_op import Session
|
||||
engines = get_engines(config, 'corepos.db.lane_op')
|
||||
config.core_lane_op_engines = engines
|
||||
config.core_lane_op_engine = engines.get('default')
|
||||
Session.configure(bind=config.core_lane_op_engine)
|
||||
|
||||
# lane_trans
|
||||
from corepos.db.lane_trans import Session
|
||||
engines = get_engines(config, 'corepos.db.lane_trans')
|
||||
config.core_lane_trans_engines = engines
|
||||
config.core_lane_trans_engine = engines.get('default')
|
||||
Session.configure(bind=config.core_lane_trans_engine)
|
||||
|
||||
# define some schema columns "late" unless not supported
|
||||
if config.get_bool('corepos.db.office_op.use_latest_columns',
|
||||
default=True, usedb=False):
|
||||
|
|
|
@ -60,6 +60,24 @@ class CoreposHandler(GenericHandler):
|
|||
|
||||
return model
|
||||
|
||||
def get_model_lane_op(self):
|
||||
"""
|
||||
Returns the :term:`data model` module for CORE Lane 'op' DB,
|
||||
i.e. :mod:`pycorepos:corepos.db.lane_op.model`.
|
||||
"""
|
||||
from corepos.db.lane_op import model
|
||||
|
||||
return model
|
||||
|
||||
def get_model_lane_trans(self):
|
||||
"""
|
||||
Returns the :term:`data model` module for CORE Lane 'trans'
|
||||
DB, i.e. :mod:`pycorepos:corepos.db.lane_trans.model`.
|
||||
"""
|
||||
from corepos.db.lane_trans import model
|
||||
|
||||
return model
|
||||
|
||||
def make_session_office_op(self, dbkey='default', **kwargs):
|
||||
"""
|
||||
Make a new :term:`db session` for the CORE Office 'op' DB.
|
||||
|
@ -99,6 +117,32 @@ class CoreposHandler(GenericHandler):
|
|||
kwargs['bind'] = self.config.core_office_arch_engines[dbkey]
|
||||
return Session(**kwargs)
|
||||
|
||||
def make_session_lane_op(self, dbkey='default', **kwargs):
|
||||
"""
|
||||
Make a new :term:`db session` for the CORE Lane 'op' DB.
|
||||
|
||||
:returns: Instance of
|
||||
:class:`pycorepos:corepos.db.lane_op.Session`.
|
||||
"""
|
||||
from corepos.db.lane_op import Session
|
||||
|
||||
if 'bind' not in kwargs:
|
||||
kwargs['bind'] = self.config.core_lane_op_engines[dbkey]
|
||||
return Session(**kwargs)
|
||||
|
||||
def make_session_lane_trans(self, dbkey='default', **kwargs):
|
||||
"""
|
||||
Make a new :term:`db session` for the CORE Lane 'trans' DB.
|
||||
|
||||
:returns: Instance of
|
||||
:class:`pycorepos:corepos.db.lane_trans.Session`.
|
||||
"""
|
||||
from corepos.db.lane_trans import Session
|
||||
|
||||
if 'bind' not in kwargs:
|
||||
kwargs['bind'] = self.config.core_lane_trans_engines[dbkey]
|
||||
return Session(**kwargs)
|
||||
|
||||
def get_office_url(self, require=False):
|
||||
"""
|
||||
Returns the base URL for the CORE Office web app.
|
||||
|
|
|
@ -49,6 +49,22 @@ in general.
|
|||
.. class:: ExtraCoreArchSessions
|
||||
|
||||
Dict of secondary CORE Office 'arch' DB sessions, if applicable.
|
||||
|
||||
.. class:: CoreLaneOpSession
|
||||
|
||||
Primary web app :term:`db session` for CORE Lane 'op' DB.
|
||||
|
||||
.. class:: CoreLaneTransSession
|
||||
|
||||
Primary web app :term:`db session` for CORE Lane 'trans' DB.
|
||||
|
||||
.. class:: ExtraCoreLaneOpSessions
|
||||
|
||||
Dict of secondary CORE Lane 'op' DB sessions, if applicable.
|
||||
|
||||
.. class:: ExtraCoreLaneTransSessions
|
||||
|
||||
Dict of secondary CORE Lane 'trans' DB sessions, if applicable.
|
||||
"""
|
||||
|
||||
from sqlalchemy.orm import sessionmaker, scoped_session
|
||||
|
@ -64,7 +80,15 @@ register(CoreTransSession)
|
|||
CoreArchSession = scoped_session(sessionmaker())
|
||||
register(CoreArchSession)
|
||||
|
||||
CoreLaneOpSession = scoped_session(sessionmaker())
|
||||
register(CoreLaneOpSession)
|
||||
|
||||
CoreLaneTransSession = scoped_session(sessionmaker())
|
||||
register(CoreLaneTransSession)
|
||||
|
||||
# nb. these start out empty but may be populated on app startup
|
||||
ExtraCoreOpSessions = {}
|
||||
ExtraCoreTransSessions = {}
|
||||
ExtraCoreArchSessions = {}
|
||||
ExtraCoreLaneOpSessions = {}
|
||||
ExtraCoreLaneTransSessions = {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue