Skip to content
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

Remove notifications for deleted instances #4899

Merged
merged 4 commits into from
Dec 13, 2024

Conversation

hardillb
Copy link
Contributor

@hardillb hardillb commented Dec 9, 2024

fixes #4845

Description

Adds afterDestroy hook to Projects table remove Notifications when Instances are deleted.

Also includes a migration to remove orphaned Notifications.

Related Issue(s)

#4845

Checklist

  • I have read the contribution guidelines
  • Suitable unit/system level tests have been added and they pass
  • Documentation has been updated
    • Upgrade instructions
    • Configuration details
    • Concepts
  • Changes flowforge.yml?
    • Issue/PR raised on FlowFuse/helm to update ConfigMap Template
    • Issue/PR raised on FlowFuse/CloudProject to update values for Staging/Production

Labels

  • Includes a DB migration? -> add the area:migration label

@hardillb hardillb added the area:migration Involves a database migration label Dec 9, 2024
@hardillb hardillb requested a review from knolleary December 9, 2024 16:59
@hardillb hardillb self-assigned this Dec 9, 2024
@hardillb
Copy link
Contributor Author

hardillb commented Dec 9, 2024

We should probably do Devices as well, but want the approach verifying first

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 39.13043% with 14 lines in your changes missing coverage. Please review.

Project coverage is 78.64%. Comparing base (6f512d8) to head (3344565).
Report is 127 commits behind head on main.

Files with missing lines Patch % Lines
.../20241209-01-remove-dead-instance-notifications.js 36.36% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4899      +/-   ##
==========================================
- Coverage   78.74%   78.64%   -0.10%     
==========================================
  Files         323      324       +1     
  Lines       15221    15254      +33     
  Branches     3496     3501       +5     
==========================================
+ Hits        11986    11997      +11     
- Misses       3235     3257      +22     
Flag Coverage Δ
backend 78.64% <39.13%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@knolleary
Copy link
Member

Can we look at doing a bulk delete sql rather than lots of individual ones?

https://sequelize.org/docs/v7/querying/delete/#deleting-in-bulk

@hardillb
Copy link
Contributor Author

I'll have another look, but we only have raw SQL access at this point (none of the models are loaded when the migrations run).

And the Notification table doesn't have a bare field with the project id that would could do a WHERE "projectId" NOT IN (SELECT "id" from Projects)

@knolleary
Copy link
Member

Good point; the reference field doesn't lend itself to using with in.

This should speed up results when found I think
Copy link
Member

@knolleary knolleary left a comment

Choose a reason for hiding this comment

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

Issue with the count query across both support db flavours.

@knolleary knolleary merged commit d636c16 into main Dec 13, 2024
17 of 18 checks passed
@knolleary knolleary deleted the remove-notifications-delete-instances branch December 13, 2024 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:migration Involves a database migration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Instance related notifications not cleared when instance deleted
2 participants