🐛 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,6 +33,9 @@ def initialize_database():
session.execute("DROP TABLE alembic_version") session.execute("DROP TABLE alembic_version")
database_manager.run_migrations() database_manager.run_migrations()
except Exception as exc: except Exception as 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}") logger.error(f"Error running migrations: {exc}")
raise RuntimeError("Error running migrations") from exc raise RuntimeError("Error running migrations") from exc
database_manager.create_db_and_tables() database_manager.create_db_and_tables()