Skip to content

Commit

Permalink
Add ondelete cascade to foreign keys in user credentials and credenti…
Browse files Browse the repository at this point in the history
…al groups
  • Loading branch information
arash77 committed Jan 3, 2025
1 parent d6b92ae commit e5c3a59
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
4 changes: 0 additions & 4 deletions lib/galaxy/webapps/galaxy/services/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit e5c3a59

Please sign in to comment.