-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: adds unique constraint on role_invite #6000
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
fix: adds unique constraint on role_invite #6000
Conversation
7f3dda9 to
604fd53
Compare
Codecov Report
@@ Coverage Diff @@
## development #6000 +/- ##
============================================
Coverage 66.28% 66.28%
============================================
Files 285 285
Lines 13995 13995
============================================
Hits 9277 9277
Misses 4718 4718Continue to review full report at Codecov.
|
a524946 to
10a9fb3
Compare
10a9fb3 to
47a61f1
Compare
83b9b1f to
4b341dd
Compare
iamareebjamal
left a comment
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.
Use unique constraint
|
@iamareebjamal you mean this - |
|
You are checking uniqueness on 3 attributes, email, role and event_id whereas the Unique Constraint has 4 attributes, that's why it's not failing |
|
@iamareebjamal actually I followed the implementation from here -
Maybe this needs to be fixed too. |
|
I'm sorry, I was wrong, the unique constraint is correct. You just haven't created the migration. How is the DB going to know about the constraint? |
4b341dd to
c71325c
Compare
uds5501
left a comment
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.
This looks good!
|
@iamareebjamal thanks a lot for help. I've fixed it. |
| WHERE R1.id < R2.id | ||
| AND R1.email = R2.email | ||
| AND R1.role_id = R2.role_id | ||
| AND R1.event_id = R2.event_id |
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.
Uhh, what?
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.
Removing duplicates, right?
So are there any foreign keys in role_invites?
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'm deleting all the past duplicate entries here and tested on my local too. When I didn't add this delete condition the upgradation raised error due to presence of duplicate entries. Is the delete statement wrong? @iamareebjamal
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.
Yes @iamareebjamal. event_id and role_id are foreignKeys
| event_id = db.Column(db.Integer, db.ForeignKey('events.id', ondelete='CASCADE')) |
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.
No, which table has role_invites as foreign key?
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'm deleting all the past duplicate entries here and tested on my local too
Problem is about data loss in production DB, if one of the deleted role invite is linked to other table
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.
@iamareebjamal I understand your concern. I've cross-checked and didn't find any model which uses role_invite as a foreign key.
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.
OK, so reverse the condition R1.id > R2.id, we want to delete all but first
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.
@iamareebjamal changed the condition.
c71325c to
94cf67a
Compare
Fixes #5986
Checklist
developmentbranch.Short description of what this resolves:
Invitations with the same email and same role can be sent more than once and it is being stored multiple times in the list of roles.
Changes proposed in this pull request: