Browse Source

Merge "SQL: only create tables in scheduler"

tags/3.6.1
Zuul 2 months ago
parent
commit
3c73474c07
1 changed files with 14 additions and 2 deletions
  1. 14
    2
      zuul/driver/sql/sqlconnection.py

+ 14
- 2
zuul/driver/sql/sqlconnection.py View File

@@ -187,7 +187,6 @@ class SQLConnection(BaseConnection):
187 187
                 self.dburi,
188 188
                 poolclass=sqlalchemy.pool.QueuePool,
189 189
                 pool_recycle=self.connection_config.get('pool_recycle', 1))
190
-            self._migrate()
191 190
 
192 191
             # If we want the objects returned from query() to be
193 192
             # usable outside of the session, we need to expunge them
@@ -200,7 +199,6 @@ class SQLConnection(BaseConnection):
200 199
                                                     autoflush=False)
201 200
             self.session = orm.scoped_session(self.session_factory)
202 201
 
203
-            self.tables_established = True
204 202
         except sa.exc.NoSuchModuleError:
205 203
             self.log.exception(
206 204
                 "The required module for the dburi dialect isn't available. "
@@ -231,6 +229,20 @@ class SQLConnection(BaseConnection):
231 229
             tag = {'table_prefix': self.table_prefix}
232 230
             alembic.command.upgrade(config, 'head', tag=tag)
233 231
 
232
+    def onLoad(self):
233
+        try:
234
+            self._migrate()
235
+            self.tables_established = True
236
+        except sa.exc.NoSuchModuleError:
237
+            self.log.exception(
238
+                "The required module for the dburi dialect isn't available. "
239
+                "SQL connection %s will be unavailable." %
240
+                self.connection_name)
241
+        except sa.exc.OperationalError:
242
+            self.log.exception(
243
+                "Unable to connect to the database or establish the required "
244
+                "tables. Connection %s is disabled" % self)
245
+
234 246
     def _setup_models(self):
235 247
         Base = declarative_base(metadata=sa.MetaData())
236 248
 

Loading…
Cancel
Save