diff --git a/src/context/service/__main__.py b/src/context/service/__main__.py index 8b39c0dedd8fd99afc11487dcb982ee8a41a3c6f..5ac91f233504a25bb787df5be9b1a36848f4e5c4 100644 --- a/src/context/service/__main__.py +++ b/src/context/service/__main__.py @@ -44,9 +44,17 @@ def main(): start_http_server(metrics_port) # Get Database Engine instance and initialize database, if needed + LOGGER.info('Getting SQLAlchemy DB Engine...') db_engine = Engine.get_engine() - if db_engine is None: return -1 - Engine.create_database(db_engine) + if db_engine is None: + LOGGER.error('Unable to get SQLAlchemy DB Engine...') + return -1 + + try: + Engine.create_database(db_engine) + except: # pylint: disable=bare-except # pragma: no cover + LOGGER.exception('Failed to check/create the database: {:s}'.format(str(db_engine.url))) + rebuild_database(db_engine) # Get message broker instance diff --git a/src/context/service/database/Engine.py b/src/context/service/database/Engine.py index 5cfe7cd4be6fefb4fe2e0921e2cd0e2b4e23c60a..5924329900dda78d7a15ce7eebc6cbc69e954f8f 100644 --- a/src/context/service/database/Engine.py +++ b/src/context/service/database/Engine.py @@ -42,12 +42,6 @@ class Engine: LOGGER.exception('Failed to connect to database: {:s}'.format(str(crdb_uri))) return None - try: - Engine.create_database(engine) - except: # pylint: disable=bare-except # pragma: no cover - LOGGER.exception('Failed to check/create to database: {:s}'.format(str(crdb_uri))) - return None - return engine @staticmethod