-
Notifications
You must be signed in to change notification settings - Fork 25
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
user_id constraint added to webpage activity table #3428
Conversation
I don't think that the Another small thing is that you actually shouldn't update |
cleaned it up, ready for review @misaugstad |
conf/evolutions/default/206.sql
Outdated
@@ -0,0 +1,7 @@ | |||
# --- !Ups | |||
DELETE FROM webpage_activity USING sidewalk_user WHERE webpage_activity.user_id = sidewalk_user.user_id AND sidewalk_user.user_id IS NULL; |
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 will only delete entries if the user_id
is null, bc it's doing an inner join? I threw your original query into chatGPT and asked it to generate one that uses a join, and it looks right to me.
My question:
translate this into using a join with the
sidewalk_user
table instead of as a subquery
DELETE FROM webpage_activity WHERE user_id IS NULL OR user_id NOT IN (SELECT user_id FROM sidewalk_user);
Suggested query
DELETE wa
FROM webpage_activity wa
LEFT JOIN sidewalk_user su ON wa.user_id = su.user_id
WHERE wa.user_id IS NULL OR su.user_id IS NULL;
And then me editing it to fit more with our typical style:
DELETE
FROM webpage_activity
LEFT JOIN sidewalk_user ON webpage_activity.user_id = sidewalk_user.user_id
WHERE webpage_activity.user_id IS NULL OR sidewalk_user.user_id IS NULL;
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.
We got here eventually 😁
Resolves #2091
Added a foreign key constraint to the user_id column in webpage activity. Had to adjust temporary_label_id in a couple format files from nullable to non-null.
Testing instructions
Things to check before submitting the PR