File tree Expand file tree Collapse file tree
src/app/core/services/database Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments