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

Username and email columns not unique #123

Open
11janci opened this issue Oct 1, 2019 · 0 comments
Open

Username and email columns not unique #123

11janci opened this issue Oct 1, 2019 · 0 comments

Comments

@11janci
Copy link

11janci commented Oct 1, 2019

Currently in the database the username and email columns are not unique:

username VARCHAR(255) NOT NULL,

email VARCHAR(255) NOT NULL,

You are enforcing uniqueness in the code during signup by searching if the username or email already exist in the database:
.then(() => getUserByEmailOrUsername(email, username))

It is better to enforce it directly in the database

username VARCHAR(255) NOT NULL UNIQUE,
email VARCHAR(255) NOT NULL UNIQUE,
  • guarantees you won't be able to insert duplicate data (with the code you might introduce some new way of inserting users in the future and forget to enforce the uniqueness)
  • allows you to get rid of the initial DB search during signup and just insert right away - if duplicate records already exist, you will get an error

Probably no action necessary, just something to keep in mind.

@11janci 11janci changed the title Username and email columns unique Username and email columns not unique Oct 1, 2019
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

No branches or pull requests

1 participant