SQL: only create tables in scheduler
If the scheduler and web processes are started simultaneously, table creation can error out. Therefore, only create tables within the scheduler process. The scheduler is the only process that calls the onLoad method. Change-Id: Ibb72e5e1af0cdd0db51744767c853318516dc22d
This commit is contained in:
parent
6a9d029834
commit
41298d51ad
|
@ -161,7 +161,6 @@ class SQLConnection(BaseConnection):
|
|||
self.dburi,
|
||||
poolclass=sqlalchemy.pool.QueuePool,
|
||||
pool_recycle=self.connection_config.get('pool_recycle', 1))
|
||||
self._migrate()
|
||||
|
||||
# If we want the objects returned from query() to be
|
||||
# usable outside of the session, we need to expunge them
|
||||
|
@ -174,7 +173,6 @@ class SQLConnection(BaseConnection):
|
|||
autoflush=False)
|
||||
self.session = orm.scoped_session(self.session_factory)
|
||||
|
||||
self.tables_established = True
|
||||
except sa.exc.NoSuchModuleError:
|
||||
self.log.exception(
|
||||
"The required module for the dburi dialect isn't available. "
|
||||
|
@ -205,6 +203,20 @@ class SQLConnection(BaseConnection):
|
|||
tag = {'table_prefix': self.table_prefix}
|
||||
alembic.command.upgrade(config, 'head', tag=tag)
|
||||
|
||||
def onLoad(self):
|
||||
try:
|
||||
self._migrate()
|
||||
self.tables_established = True
|
||||
except sa.exc.NoSuchModuleError:
|
||||
self.log.exception(
|
||||
"The required module for the dburi dialect isn't available. "
|
||||
"SQL connection %s will be unavailable." %
|
||||
self.connection_name)
|
||||
except sa.exc.OperationalError:
|
||||
self.log.exception(
|
||||
"Unable to connect to the database or establish the required "
|
||||
"tables. Connection %s is disabled" % self)
|
||||
|
||||
def _setup_models(self):
|
||||
Base = declarative_base(metadata=sa.MetaData())
|
||||
|
||||
|
|
Loading…
Reference in New Issue