Skip to content

Commit f24b922

Browse files
author
jc
committed
Fixing tests
1 parent 3a059a3 commit f24b922

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/app/core/services/database/db_manage.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,22 @@ def __init__(self) -> None:
1616
# Build the database URL with the resolved password
1717
def create_all(self) -> None:
1818
"""Create all database tables."""
19-
from sqlalchemy.exc import ProgrammingError
19+
from sqlalchemy.exc import IntegrityError, ProgrammingError
2020
from sqlmodel import SQLModel
2121

2222
get_metadata() # Ensure all tables are imported and registered
2323

2424
try:
2525
SQLModel.metadata.create_all(self._engine)
2626
logger.info("Database initialized with tables.")
27-
except ProgrammingError as e:
27+
except (ProgrammingError, IntegrityError) as e:
2828
# Handle race condition when multiple workers try to create tables
29-
if "already exists" in str(e):
30-
logger.debug("Tables already exist, skipping creation")
29+
# ProgrammingError: relation already exists
30+
# IntegrityError: duplicate key in pg_type catalog (partial table creation)
31+
error_msg = str(e).lower()
32+
if "already exists" in error_msg or "duplicate key" in error_msg:
33+
logger.debug(
34+
f"Tables already exist or partially created, skipping: {type(e).__name__}"
35+
)
3136
else:
3237
raise

0 commit comments

Comments
 (0)