-
Notifications
You must be signed in to change notification settings - Fork 45
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
[153] unique constraints #237
[153] unique constraints #237
Conversation
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.
One additional thing - would be great to have some meaningful human-readable description of alembic migration (see: https://alembic.sqlalchemy.org/en/latest/autogenerate.html)
backend/models.py
Outdated
email = Column(String(200)) | ||
first_name = Column(String(50), nullable=False) | ||
last_name = Column(String(50), nullable=False) | ||
email = Column(String(200), unique=True, nullable=False) | ||
github = Column(String(200), default="") |
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.
shouldn't be github
login also unique?
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.
Could be. ;-)
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've made some amendments here.
github = fields.Str(validate=[validate.Length(max=200)]) | ||
last_name = fields.Str(required=True, validate=[validate.Length(max=50)]) | ||
email = fields.Email(required=True, validate=[validate.Length(max=200)]) | ||
github = fields.Str(required=True, validate=[validate.Length(max=200)]) | ||
hacknights = fields.Nested("HacknightSchema", exclude=("participants",), many=True) |
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 would consider validating minimum length of database not-nullable fields (first_name, last_name, github) to avoid adding participants with empty strings ("").
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 will create a separate ticket for adding regex validation for all fields (just not to create big pull requests).
backend/resources/participant.py
Outdated
if ( | ||
Participant.query.filter(Participant.email == json_data["email"]).first() | ||
is not None | ||
): |
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 that is not None
could be removed.
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.
Is not worth to add some tests for those changes? What do You think?
first_name = fields.Str(required=True, validate=[validate.Length(min=3, max=50)]) | ||
last_name = fields.Str(required=True, validate=[validate.Length(min=3, max=50)]) | ||
email = fields.Email(required=True, validate=[validate.Length(min=5, max=200)]) | ||
github = fields.Str(required=True, validate=[validate.Length(min=5, max=200)]) |
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.
backend/resources/participant.py
Outdated
@@ -29,6 +29,21 @@ def post(self): | |||
except ValidationError as err: | |||
return (err.messages), HTTPStatus.BAD_REQUEST | |||
|
|||
if Participant.query.filter(Participant.email == json_data["email"]).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.
Could be:
if Participant.query.filter_by(email=json_data["email"]).first():
backend/resources/participant.py
Outdated
if ( | ||
Participant.query.filter(Participant.github == json_data["github"]).first() | ||
is not None | ||
): |
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 that is not None
could be removed.
Also You could use here:
if Participant.query.filter_by(github=json_data["github"]).first():
To test:
first_name
,last_name