🐛 fix(utils.py): handle exception when running migrations to ignore "already exists" error and prevent unnecessary error logging and raising of RuntimeError

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-28 14:43:58 -03:00
commit 4320b127d3

View file

@ -33,8 +33,11 @@ def initialize_database():
session.execute("DROP TABLE alembic_version")
database_manager.run_migrations()
except Exception as exc:
logger.error(f"Error running migrations: {exc}")
raise RuntimeError("Error running migrations") from exc
# if the exception involves tables already existing
# we can ignore it
if "already exists" not in str(exc):
logger.error(f"Error running migrations: {exc}")
raise RuntimeError("Error running migrations") from exc
database_manager.create_db_and_tables()
logger.debug("Database initialized")