-
Notifications
You must be signed in to change notification settings - Fork 999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cascade Role Invitations delete while deleting project #17819
base: main
Are you sure you want to change the base?
Conversation
warehouse/manage/views/__init__.py
Outdated
# Delete all role invitations for this project | ||
( | ||
request.db.query(RoleInvitation) | ||
.filter(RoleInvitation.project == project) | ||
.delete() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should probably be done with an ondelete="CASCADE"
, similar to #3182.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @di , thank you for providing the reference, I tried adding cascade to "invitations" in Project Model and I was able to delete the projects with pending role_invitations
Although I did create alembic migrations as was the approach in previous issues, but I am not sure if they are needed here
PS - Below is my migration file (Not include in PR)
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Add cascade delete to RoleInvitation
Revision ID: a39f43699c08
Revises: 6de76386dbf4
Create Date: 2025-03-20 23:16:20.429394
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = "a39f43699c08"
down_revision = "6de76386dbf4"
def upgrade() -> None:
"""Upgrade schema: Add cascade delete to RoleInvitation.project_id at DB level"""
op.execute(
"ALTER TABLE role_invitations "
"DROP CONSTRAINT IF EXISTS role_invitations_project_id_fkey"
)
op.create_foreign_key(
"role_invitations_project_id_fkey",
"role_invitations",
"projects",
["project_id"],
["id"],
ondelete="CASCADE" # Enforcing CASCADE at the DB level
)
def downgrade() -> None:
"""Downgrade schema: Remove cascade delete from RoleInvitation.project_id"""
op.drop_constraint("role_invitations_project_id_fkey", "role_invitations", type_="foreignkey")
op.create_foreign_key(
"role_invitations_project_id_fkey",
"role_invitations",
"projects",
["project_id"],
["id"]
)
Fixes: #17751