-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[WEB-2092] chore: soft delete migration #5286
Conversation
WalkthroughThe recent changes enhance the management of soft deletions across various models in the application. By integrating a Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant View
participant Model
User->>View: Request deletion of record
View->>Model: Call delete() without soft parameter
Model-->>View: Respond with deletion status
View-->>User: Confirmation of deletion
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (3)
apiserver/plane/db/models/page.py (1)
237-244
: Ensuredeleted_at
is considered inProjectPage
operations.The operations involving the
ProjectPage
model do not currently account for thedeleted_at
field in their conditions. To respect the new uniqueness constraints, please update these operations to include conditions that ensuredeleted_at
is null when necessary.
apiserver/plane/bgtasks/dummy_data_task.py
apiserver/plane/app/views/search/base.py
apiserver/plane/app/views/page/base.py
apiserver/plane/app/serializers/page.py
Analysis chain
LGTM! But verify the function usage in the codebase.
The changes to the
Meta
class ofProjectPage
are approved.However, ensure that all queries and operations involving
ProjectPage
are updated to account for the new uniqueness constraints.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all queries and operations involving `ProjectPage` are updated to account for the new uniqueness constraints. # Test: Search for the `ProjectPage` model usage. Expect: Queries and operations consider the new constraints. rg --type python -A 5 $'ProjectPage'Length of output: 66
Script:
#!/bin/bash # Description: Verify all queries and operations involving `ProjectPage` are updated to account for the new uniqueness constraints. # Test: Search for the `ProjectPage` model usage. Expect: Queries and operations consider the new constraints. rg 'ProjectPage' --glob '*.py' -A 5Length of output: 7423
Script:
#!/bin/bash # Description: Verify all queries and operations involving `ProjectPage` are updated to account for the new uniqueness constraints. # Test: Search for the usage of `ProjectPage` and check for conditions involving `deleted_at`. rg 'ProjectPage' apiserver/plane/bgtasks/dummy_data_task.py -A 5 rg 'ProjectPage' apiserver/plane/app/views/search/base.py -A 5 rg 'ProjectPage' apiserver/plane/app/views/page/base.py -A 5 rg 'ProjectPage' apiserver/plane/app/serializers/page.py -A 5Length of output: 1484
apiserver/plane/db/models/workspace.py (1)
220-227
: Ensuredeleted_at
field is indexed.The
deleted_at
field is not currently indexed in theWorkspaceMemberInvite
model. Given its inclusion in theunique_together
constraint and the newconstraints
list, indexing this field is crucial for performance. Please add an index to thedeleted_at
field.
- File:
apiserver/plane/db/models/workspace.py
- Lines: 220-227
Analysis chain
Ensure
deleted_at
field exists and is indexed.The addition of
deleted_at
to theunique_together
constraint and the newconstraints
list is correct for handling soft deletions. Ensure that thedeleted_at
field exists in the model and is indexed for performance.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the `deleted_at` field exists and is indexed in the `WorkspaceMemberInvite` model. # Test: Search for the `deleted_at` field definition. Expect: The field should be defined and indexed. rg --type python 'deleted_at' --context 5Length of output: 72
Script:
#!/bin/bash # Description: Verify that the `deleted_at` field exists and is indexed in the `WorkspaceMemberInvite` model. # Test: Search for the `deleted_at` field definition. Expect: The field should be defined and indexed. rg --type py 'deleted_at' --context 5Length of output: 183000
Script:
#!/bin/bash # Description: Verify if the `deleted_at` field is indexed in the `WorkspaceMemberInvite` model. # Test: Search for index definitions on the `deleted_at` field in the `WorkspaceMemberInvite` model. rg --type py 'deleted_at' --context 10 | grep -i 'index'Length of output: 149
apiserver/plane/app/views/module/base.py (1)
843-843
: Verify the deletion behavior.The removal of the
soft=False
parameter from thedelete
method call inapiserver/plane/app/views/module/base.py
changes the deletion behavior to a soft delete by default. This aligns with the implementation found inapiserver/plane/db/mixins.py
, where thedelete
method performs a soft delete unless explicitly overridden. Ensure that this change aligns with the intended functionality.
- File:
apiserver/plane/app/views/module/base.py
- Relevant Implementation:
apiserver/plane/db/mixins.py
(soft delete by default)Analysis chain
Verify the deletion behavior.
The removal of the
soft=False
parameter from thedelete
method call potentially changes the deletion behavior to a soft delete. Ensure that this change aligns with the intended functionality.
Let's correct the previous script to properly search for the
delete
method implementation in theUserFavorite
model.
Let's search for the
delete
method implementation across all Python files to locate its definition and understand its behavior.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the deletion behavior of the `delete` method on `UserFavorite` model. # Test: Search for the `delete` method implementation in the `UserFavorite` model. rg --type python -A 5 $'class UserFavorite' | rg 'def delete'Length of output: 93
Script:
#!/bin/bash # Description: Verify the deletion behavior of the `delete` method on `UserFavorite` model. # Test: Search for the `delete` method implementation in the `UserFavorite` model. rg --type py -A 5 'class UserFavorite' | rg 'def delete'Length of output: 58
Script:
#!/bin/bash # Description: Verify the deletion behavior of the `delete` method across the codebase. # Test: Search for the `delete` method implementation across all Python files. rg --type py 'def delete' -A 5Length of output: 19956
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
web/public/sw.js.map
is excluded by!**/*.map
Files selected for processing (21)
- apiserver/plane/app/serializers/issue.py (2 hunks)
- apiserver/plane/app/views/cycle/base.py (1 hunks)
- apiserver/plane/app/views/module/base.py (1 hunks)
- apiserver/plane/app/views/page/base.py (2 hunks)
- apiserver/plane/app/views/project/base.py (1 hunks)
- apiserver/plane/app/views/search/issue.py (1 hunks)
- apiserver/plane/app/views/view/base.py (1 hunks)
- apiserver/plane/db/migrations/0073_alter_commentreaction_unique_together_and_more.py (1 hunks)
- apiserver/plane/db/models/cycle.py (1 hunks)
- apiserver/plane/db/models/dashboard.py (1 hunks)
- apiserver/plane/db/models/deploy_board.py (1 hunks)
- apiserver/plane/db/models/estimate.py (2 hunks)
- apiserver/plane/db/models/favorite.py (1 hunks)
- apiserver/plane/db/models/inbox.py (1 hunks)
- apiserver/plane/db/models/issue.py (9 hunks)
- apiserver/plane/db/models/issue_type.py (2 hunks)
- apiserver/plane/db/models/module.py (3 hunks)
- apiserver/plane/db/models/page.py (2 hunks)
- apiserver/plane/db/models/project.py (2 hunks)
- apiserver/plane/db/models/state.py (2 hunks)
- apiserver/plane/db/models/workspace.py (6 hunks)
Additional comments not posted (49)
apiserver/plane/db/models/issue_type.py (3)
3-3
: Import statement forQ
added.The import statement for
Q
fromdjango.db.models
is necessary for the conditional unique constraint.
19-19
: Update unique constraint to includedeleted_at
.The
unique_together
constraint now includesdeleted_at
, allowing for multiple entries with the samename
andproject
as long as they have differentdeleted_at
values.
20-26
: New unique constraint with condition added.The new
models.UniqueConstraint
ensures that the combination ofname
andproject
remains unique only whendeleted_at
is null. This enhances the model's ability to handle soft deletions.apiserver/plane/db/models/deploy_board.py (2)
49-49
: Update unique constraint to includedeleted_at
.The
unique_together
constraint now includesdeleted_at
, allowing for multiple entries with the sameentity_name
andentity_identifier
as long as they have differentdeleted_at
values.
50-56
: New unique constraint with condition added.The new
models.UniqueConstraint
ensures that the combination ofentity_name
andentity_identifier
remains unique only whendeleted_at
is null. This enhances the model's ability to handle soft deletions.apiserver/plane/db/models/estimate.py (3)
4-4
: Import statement forQ
added.The import statement for
Q
fromdjango.db.models
is necessary for the conditional unique constraint.
23-23
: Update unique constraint to includedeleted_at
.The
unique_together
constraint now includesdeleted_at
, allowing for multiple entries with the samename
andproject
as long as they have differentdeleted_at
values.
24-30
: New unique constraint with condition added.The new
models.UniqueConstraint
ensures that the combination ofname
andproject
remains unique only whendeleted_at
is null. This enhances the model's ability to handle soft deletions.apiserver/plane/db/models/favorite.py (2)
34-34
: LGTM! Theunique_together
constraint update supports soft delete functionality.The addition of the
deleted_at
field to theunique_together
constraint ensures that the combination ofentity_type
,user
,entity_identifier
, anddeleted_at
is unique, which is crucial for implementing soft deletes.
35-41
: LGTM! The newUniqueConstraint
enhances data integrity.The new
UniqueConstraint
ensures that the combination ofentity_type
,entity_identifier
, anduser
is unique whendeleted_at
is null, which helps maintain data integrity by preventing conflicts between active and deleted records.apiserver/plane/db/models/inbox.py (2)
22-22
: LGTM! Theunique_together
constraint update supports soft delete functionality.The addition of the
deleted_at
field to theunique_together
constraint ensures that the combination ofname
,project
, anddeleted_at
is unique, which is crucial for implementing soft deletes.
23-29
: LGTM! The newUniqueConstraint
enhances data integrity.The new
UniqueConstraint
ensures that the combination ofname
andproject
is unique whendeleted_at
is null, which helps maintain data integrity by preventing conflicts between active and deleted records.apiserver/plane/db/models/state.py (2)
40-40
: LGTM! Theunique_together
constraint update supports soft delete functionality.The addition of the
deleted_at
field to theunique_together
constraint ensures that the combination ofname
,project
, anddeleted_at
is unique, which is crucial for implementing soft deletes.
41-47
: LGTM! The newUniqueConstraint
enhances data integrity.The new
UniqueConstraint
ensures that the combination ofname
andproject
is unique whendeleted_at
is null, which helps maintain data integrity by preventing conflicts between active and deleted records.apiserver/plane/db/models/dashboard.py (2)
91-91
: Enhance uniqueness constraint to includedeleted_at
.Adding
deleted_at
to theunique_together
constraint ensures that soft-deleted records do not violate uniqueness constraints. This is a good practice for handling soft deletions.
92-98
: Introduce conditional uniqueness constraint for active records.The new
UniqueConstraint
ensures that the combination ofwidget
anddashboard
is unique only whendeleted_at
is null. This prevents conflicts with active records while allowing soft-deleted records to coexist.apiserver/plane/app/views/search/issue.py (2)
57-58
: Enhance filtering logic to exclude soft-deleted related issues.Adding
issue_related__deleted_at__isnull=True
ensures that only non-deleted related issues are considered. This improves the integrity of the data returned by the view.
61-62
: Enhance filtering logic to exclude soft-deleted related issues.Adding
issue_related__deleted_at__isnull=True
ensures that only non-deleted related issues are considered. This improves the integrity of the data returned by the view.apiserver/plane/db/models/cycle.py (2)
164-164
: Enhance uniqueness constraint to includedeleted_at
.Adding
deleted_at
to theunique_together
constraint ensures that soft-deleted records do not violate uniqueness constraints. This is a good practice for handling soft deletions.
165-171
: Introduce conditional uniqueness constraint for active records.The new
UniqueConstraint
ensures that the combination ofcycle
anduser
is unique only whendeleted_at
is null. This prevents conflicts with active records while allowing soft-deleted records to coexist.apiserver/plane/db/models/module.py (3)
133-140
: LGTM! But verify the function usage in the codebase.The changes to the
Meta
class ofModuleMember
are approved.However, ensure that all queries and operations involving
ModuleMember
are updated to account for the new uniqueness constraints.
239-246
: LGTM! But verify the function usage in the codebase.The changes to the
Meta
class ofModuleUserProperties
are approved.However, ensure that all queries and operations involving
ModuleUserProperties
are updated to account for the new uniqueness constraints.
159-166
: LGTM! But verify the function usage in the codebase.The changes to the
Meta
class ofModuleIssue
are approved.However, ensure that all queries and operations involving
ModuleIssue
are updated to account for the new uniqueness constraints.apiserver/plane/db/models/page.py (1)
266-273
: LGTM! But verify the function usage in the codebase.The changes to the
Meta
class ofTeamPage
are approved.However, ensure that all queries and operations involving
TeamPage
are updated to account for the new uniqueness constraints.apiserver/plane/db/models/project.py (2)
334-341
: LGTM! But verify the function usage in the codebase.The changes to the
Meta
class ofProjectPublicMember
are approved.However, ensure that all queries and operations involving
ProjectPublicMember
are updated to account for the new uniqueness constraints.
217-224
: LGTM! But verify the function usage in the codebase.The changes to the
Meta
class ofProjectMember
are approved.However, ensure that all queries and operations involving
ProjectMember
are updated to account for the new uniqueness constraints.apiserver/plane/db/models/workspace.py (5)
188-195
: Ensuredeleted_at
field exists and is indexed.The addition of
deleted_at
to theunique_together
constraint and the newconstraints
list is correct for handling soft deletions. Ensure that thedeleted_at
field exists in the model and is indexed for performance.
288-295
: Ensuredeleted_at
field exists and is indexed.The addition of
deleted_at
to theunique_together
constraint and the newconstraints
list is correct for handling soft deletions. Ensure that thedeleted_at
field exists in the model and is indexed for performance.
257-264
: Ensuredeleted_at
field exists and is indexed.The addition of
deleted_at
to theunique_together
constraint and the newconstraints
list is correct for handling soft deletions. Ensure that thedeleted_at
field exists in the model and is indexed for performance.
318-325
: Ensuredeleted_at
field exists and is indexed.The addition of
deleted_at
to theunique_together
constraint and the newconstraints
list is correct for handling soft deletions. Ensure that thedeleted_at
field exists in the model and is indexed for performance.
350-357
: Ensuredeleted_at
field exists and is indexed.The addition of
deleted_at
to theunique_together
constraint and the newconstraints
list is correct for handling soft deletions. Ensure that thedeleted_at
field exists in the model and is indexed for performance.apiserver/plane/app/views/view/base.py (2)
Line range hint
389-389
:
Verify the default behavior ofdelete
method.The removal of the
soft=False
argument suggests that the default behavior of thedelete
method will be used. Ensure that this aligns with the intended deletion behavior (soft or hard delete).
477-477
: Verify the default behavior ofdelete
method.The removal of the
soft=False
argument suggests that the default behavior of thedelete
method will be used. Ensure that this aligns with the intended deletion behavior (soft or hard delete).Verification successful
Verify the default behavior of
delete
method.The default behavior of the
delete
method in theUserFavorite
model is a soft delete, as indicated by thesoft=True
default parameter in thedelete
method defined inapiserver/plane/db/mixins.py
. Ensure that this aligns with the intended deletion behavior (soft or hard delete).
- File:
apiserver/plane/db/mixins.py
- Line:
def delete(self, using=None, soft=True, *args, **kwargs):
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the default behavior of the `delete` method in the `UserFavorite` model. # Test: Search for the `delete` method definition. Expect: The method should be defined with the correct default behavior. rg --type python 'def delete' --context 5Length of output: 74
Script:
#!/bin/bash # Description: Verify the default behavior of the `delete` method in the `UserFavorite` model. # Search for the `delete` method definition in Python files. rg --type py 'def delete' --context 5 # Additionally, search for the `UserFavorite` model to narrow down the context. rg --type py 'class UserFavorite' --context 10Length of output: 36385
apiserver/plane/app/serializers/issue.py (2)
536-536
: Approved: Addeddeleted_at
toread_only_fields
.Including
deleted_at
inread_only_fields
ensures the field is immutable through this serializer, which is appropriate for soft deletion.
555-555
: Approved: Addeddeleted_at
toread_only_fields
.Including
deleted_at
inread_only_fields
ensures the field is immutable through this serializer, which is appropriate for soft deletion.apiserver/plane/app/views/project/base.py (1)
602-602
: Approved: Removedsoft=False
fromdelete
method.Removing the
soft=False
argument ensures that the default deletion behavior is used, aligning with the shift towards soft deletion.apiserver/plane/db/models/issue.py (8)
298-305
: Approved: Addeddeleted_at
tounique_together
and newconstraints
list.Including
deleted_at
in theunique_together
constraint and adding the newconstraints
list ensures that uniqueness is maintained only for non-deleted records, which is appropriate for soft deletion.
326-333
: Approved: Addeddeleted_at
tounique_together
and newconstraints
list.Including
deleted_at
in theunique_together
constraint and adding the newconstraints
list ensures that uniqueness is maintained only for non-deleted records, which is appropriate for soft deletion.
354-361
: Approved: Addeddeleted_at
tounique_together
and newconstraints
list.Including
deleted_at
in theunique_together
constraint and adding the newconstraints
list ensures that uniqueness is maintained only for non-deleted records, which is appropriate for soft deletion.
536-543
: Approved: Addeddeleted_at
tounique_together
and newconstraints
list.Including
deleted_at
in theunique_together
constraint and adding the newconstraints
list ensures that uniqueness is maintained only for non-deleted records, which is appropriate for soft deletion.
641-648
: Approved: Addeddeleted_at
tounique_together
and newconstraints
list.Including
deleted_at
in theunique_together
constraint and adding the newconstraints
list ensures that uniqueness is maintained only for non-deleted records, which is appropriate for soft deletion.
670-677
: Approved: Addeddeleted_at
tounique_together
and newconstraints
list.Including
deleted_at
in theunique_together
constraint and adding the newconstraints
list ensures that uniqueness is maintained only for non-deleted records, which is appropriate for soft deletion.
701-708
: Approved: Addeddeleted_at
tounique_together
and newconstraints
list.Including
deleted_at
in theunique_together
constraint and adding the newconstraints
list ensures that uniqueness is maintained only for non-deleted records, which is appropriate for soft deletion.
739-746
: Approved: Addeddeleted_at
tounique_together
and newconstraints
list.Including
deleted_at
in theunique_together
constraint and adding the newconstraints
list ensures that uniqueness is maintained only for non-deleted records, which is appropriate for soft deletion.apiserver/plane/db/migrations/0073_alter_commentreaction_unique_together_and_more.py (4)
8-10
: LGTM!The migration dependencies are correctly specified.
145-717
: LGTM!The
deleted_at
field is consistently added to multiple models with the correct field definition.
719-857
: LGTM!The unique constraints are correctly altered to include the
deleted_at
field, ensuring that soft-deleted records do not violate unique constraints.
858-1129
: LGTM!The unique constraints with conditions are correctly added to multiple models, ensuring uniqueness when
deleted_at
is null.apiserver/plane/app/views/cycle/base.py (1)
1157-1157
: Verify the deletion behavior.The removal of the
soft=False
parameter from thedelete
method call potentially changes the deletion behavior to a soft delete. Ensure that this change aligns with the intended functionality.
@@ -401,7 +386,7 @@ def destroy(self, request, slug, project_id, pk): | |||
entity_identifier=pk, | |||
entity_type="page", | |||
) | |||
page_favorite.delete(soft=False) | |||
page_favorite.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.
Re-add access control check for page deletion.
The removal of the conditional check that restricted the deletion of a page to only its owner or an admin significantly alters the access control logic. This change potentially allows unauthorized deletions. Re-add the access control check to ensure only authorized users can delete a page.
- if not page.owned_by_id != request.user.id and not (
- ProjectMember.objects.filter(
- workspace__slug=slug,
- member=request.user,
- role=20,
- project_id=project_id,
- is_active=True,
- ).exists()
- ):
- return Response(
- {"error": "Only admin or owner can delete the page"},
- status=status.HTTP_403_FORBIDDEN,
- )
Committable suggestion was skipped due to low confidence.
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- apiserver/plane/app/views/page/base.py (3 hunks)
Additional comments not posted (3)
apiserver/plane/app/views/page/base.py (3)
336-340
: Enhanced security: Ensure the page is archived before deletion.The added check ensures that a page must be archived before it can be deleted, which improves the integrity of the deletion process.
Line range hint
342-348
:
Enhanced security: Access control for page deletion.The re-added access control check ensures that only the owner or an admin can delete a page, preventing unauthorized deletions.
389-389
: LGTM! Simplified deletion of favorite pages.The deletion of a favorite page is straightforward and does not require additional access control checks.
chore:
Issue Link: WEB-2092
Summary by CodeRabbit
New Features
deleted_at
field in uniqueness constraints for several models.Bug Fixes
Documentation