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

Email verification DB fields #258

Merged
merged 6 commits into from Mar 1, 2023
Merged

Email verification DB fields #258

merged 6 commits into from Mar 1, 2023

Conversation

pdeziel
Copy link
Contributor

@pdeziel pdeziel commented Feb 28, 2023

Scope of changes

This adds a migration to add the email verification fields to the user table in the DB and updates the SQL handling code to create/read/update the new fields.

Fixes SC-14153

Type of change

  • new feature
  • bug fix
  • documentation
  • testing
  • technical debt
  • other (describe)

Acceptance criteria

Describe how reviewers can test this change to be sure that it works correctly. Add a checklist if possible.

Author checklist

  • I have manually tested the change and/or added automation in the form of unit tests or integration tests
  • I have updated the dependencies list
  • I have recompiled and included new protocol buffers to reflect changes I made
  • I have added new test fixtures as needed to support added tests
  • Check this box if a reviewer can merge this pull request after approval (leave it unchecked if you want to do it yourself)
  • I have moved the associated Shortcut story to "Ready for Review"

Reviewer(s) checklist

  • Any new user-facing content that has been added for this PR has been QA'ed to ensure correct grammar, spelling, and understandability.
  • Are there any TODOs in this PR that should be turned into stories?

@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #14153: Email Token Database Migration.

ALTER TABLE users ADD COLUMN email_verification_expires TEXT DEFAULT NULL;

-- Token provided by the user to verify their email address.
ALTER TABLE users ADD COLUMN email_verification_token TEXT DEFAULT NULL;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to add a UNIQUE constraint here because we will need to look up the user record by the token. However, it seems that it's not allowed for the ALTER TABLE statement. Realistically it shouldn't matter since it's unlikely that two hashes would be the same but I was wondering if we wanted the constraint anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

The UNIQUE constraint also makes lookups faster since there is an index, so we probably would want the constraint. When you say it's not allowed is the problem that you can't do

ALTER TABLE users ADD COLUMN email_verification_token TEXT UNIQUE DEFAULT NULL?

Is it possible to do

CREATE UNIQUE INDEX unique_email_verification_token ON users (email_verification_token);?

(note that SQLite does allow nullable unique fields and multiple NULL values do not count towards uniqueness -- but this is a SQLite thing not a SQL thing -- https://stackoverflow.com/questions/22699409/sqlite-null-and-unique).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I wasn't able to apply the constraint on the token column but I was able to add a unique index.

Copy link
Contributor

@bbengfort bbengfort left a comment

Choose a reason for hiding this comment

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

Looks good - thanks for updating the model!

ALTER TABLE users ADD COLUMN email_verification_expires TEXT DEFAULT NULL;

-- Token provided by the user to verify their email address.
ALTER TABLE users ADD COLUMN email_verification_token TEXT DEFAULT NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

The UNIQUE constraint also makes lookups faster since there is an index, so we probably would want the constraint. When you say it's not allowed is the problem that you can't do

ALTER TABLE users ADD COLUMN email_verification_token TEXT UNIQUE DEFAULT NULL?

Is it possible to do

CREATE UNIQUE INDEX unique_email_verification_token ON users (email_verification_token);?

(note that SQLite does allow nullable unique fields and multiple NULL values do not count towards uniqueness -- but this is a SQLite thing not a SQL thing -- https://stackoverflow.com/questions/22699409/sqlite-null-and-unique).

@pdeziel pdeziel merged commit 2dbb2fb into main Mar 1, 2023
@pdeziel pdeziel deleted the sc-14153 branch March 1, 2023 16:57
daniellemaxwell pushed a commit that referenced this pull request Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants