-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Implemented raw sql replacing sqlalchemy in me endpoint #1334
Conversation
I will fix the test cases related to the user. |
src/backend/app/auth/auth_routes.py
Outdated
INSERT INTO users ( | ||
id, username, profile_img, role, mapping_level, |
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 could possibly be simplified by the suggestion Ping made, with an 'upsert' query.
Something like
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...)
ON CONFLICT (id, username)
DO UPDATE SET column1 = value1, column2 = value2, ...;
To make this work do we need a migration to ensure the username field has UNIQUE
specified? Both changes combined would simplify this query a lot π
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, Sure. By the way, the username field was already a unique field.
updated the sql using |
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.
Looks great!
Just a few minor points and it can be merged
src/backend/app/auth/auth_routes.py
Outdated
get_sql = text( | ||
""" | ||
SELECT users.*, | ||
COALESCE(user_roles.project_id) as project_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.
Coalesce could be removed here, as it's for merging two values together.
It's useful to set the default value to mapper below, but not needed for the user role or org manager parts π
src/backend/app/auth/auth_routes.py
Outdated
get_sql, | ||
{"user_id": user_data.id}, | ||
) | ||
db_user = result.fetchall() |
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.
.first() will return a single value, so that you don't have to index with [0] below. Then you also can avoid needing the for loop too π
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, you are right. Great!
Thanks for the feedback!!
What type of PR is this? (check all applicable)
Related Issue
Describe this PR
One problem I encountered while performing the insert action was that I needed to mention all the not null fields even though they have default values, unlike those handled by Alchemy automatically since we do not have the default values set at the database level.
Screenshots
Different Responses:
Checklist before requesting a review
[optional] What gif best describes this PR or how it makes you feel?