From e5c3a597e36e7232b772d74fed2eb9ea885fb733 Mon Sep 17 00:00:00 2001 From: Arash Date: Fri, 3 Jan 2025 15:05:22 +0100 Subject: [PATCH] Add ondelete cascade to foreign keys in user credentials and credential groups --- lib/galaxy/model/__init__.py | 6 ++++-- lib/galaxy/webapps/galaxy/services/credentials.py | 4 ---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index fb5a5ae459ff..e20bdf4081e1 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -11618,7 +11618,9 @@ class UserCredentials(Base): reference: Mapped[str] = mapped_column(nullable=False) source_type: Mapped[str] = mapped_column(nullable=False) source_id: Mapped[str] = mapped_column(nullable=False) - current_group_id: Mapped[int] = mapped_column(ForeignKey("user_credentials_group.id"), index=True, nullable=True) + current_group_id: Mapped[int] = mapped_column( + ForeignKey("user_credentials_group.id", ondelete="CASCADE"), index=True, nullable=True + ) create_time: Mapped[Optional[datetime]] = mapped_column(default=now) update_time: Mapped[Optional[datetime]] = mapped_column(default=now, onupdate=now) @@ -11632,7 +11634,7 @@ class CredentialsGroup(Base): id: Mapped[int] = mapped_column(primary_key=True) name: Mapped[str] = mapped_column(nullable=False) - user_credentials_id: Mapped[int] = mapped_column(ForeignKey("user_credentials.id"), index=True) + user_credentials_id: Mapped[int] = mapped_column(ForeignKey("user_credentials.id", ondelete="CASCADE"), index=True) create_time: Mapped[Optional[datetime]] = mapped_column(default=now) update_time: Mapped[Optional[datetime]] = mapped_column(default=now, onupdate=now) diff --git a/lib/galaxy/webapps/galaxy/services/credentials.py b/lib/galaxy/webapps/galaxy/services/credentials.py index 9d93545ea470..0c99559ce0c8 100644 --- a/lib/galaxy/webapps/galaxy/services/credentials.py +++ b/lib/galaxy/webapps/galaxy/services/credentials.py @@ -70,9 +70,6 @@ def delete_service_credentials( """Deletes all credentials for a specific service.""" user_credentials = self._user_credentials(trans, user_id=user_id, user_credentials_id=user_credentials_id) rows_to_be_deleted = [item for uc in user_credentials for item in uc] - rows_to_be_deleted.sort( - key=lambda item: (isinstance(item, UserCredentials), isinstance(item, CredentialsGroup)) - ) self._delete_credentials(trans.sa_session, rows_to_be_deleted) def delete_credentials( @@ -84,7 +81,6 @@ def delete_credentials( """Deletes a specific credential group.""" user_credentials = self._user_credentials(trans, user_id=user_id, group_id=group_id) rows_to_be_deleted = [item for uc in user_credentials for item in uc if not isinstance(item, UserCredentials)] - rows_to_be_deleted.sort(key=lambda item: isinstance(item, CredentialsGroup)) self._delete_credentials(trans.sa_session, rows_to_be_deleted) def _user_credentials(