Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions app/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,21 @@ def get_inference_deployment_records(self, **kwargs) -> Sequence[InferenceDeploy

def create_tables(self) -> None:
"""Create the database tables, if they don't already exist."""
with self._engine.begin() as connection:
Base.metadata.create_all(connection)
try:
with self._engine.begin() as connection:
Base.metadata.create_all(connection, checkfirst=True)
except Exception as e:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be more specific in the Exception that we handle here?

# If tables already exist (race condition with another worker), that's fine
logger.debug(f"Error creating tables (likely they already exist): {e}")

def drop_tables(self) -> None:
"""Drop all tables in the database."""
with self._engine.begin() as connection:
Base.metadata.drop_all(connection)
try:
with self._engine.begin() as connection:
Base.metadata.drop_all(connection, checkfirst=True)
except Exception as e:
# If tables don't exist yet, that's fine - we're about to create them
logger.debug(f"Error dropping tables (likely they don't exist yet): {e}")

def reset_database(self) -> None:
"""Reset the database by deleting all tables and then recreating them."""
Expand Down
Loading