🐛 fix(utils.py): improve error handling in initialize_database() function

The `initialize_database()` function now handles two specific exceptions: "overlaps with other requested revisions" and "Can't locate revision identified by". If either of these exceptions occur, they will not be raised and instead the `alembic_version` table will be deleted. This change improves the error handling and ensures that the database is properly initialized.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-10-07 12:03:51 -03:00
commit 61a5c9dcdb

View file

@ -32,7 +32,11 @@ def initialize_database():
try:
database_service.run_migrations()
except CommandError as exc:
if "Can't locate revision identified by" not in str(exc):
# if "overlaps with other requested revisions" or "Can't locate revision identified by"
# are not in the exception, we can't handle it
if "overlaps with other requested revisions" not in str(
exc
) and "Can't locate revision identified by" not in str(exc):
raise exc
# This means there's wrong revision in the DB
# We need to delete the alembic_version table