factorialLabs / beam-server

Beam cool sites to your friends' web browser!
0 stars 2 forks source link

Setup SQL and Hookup User Model #5

Open Deon opened 7 years ago

Deon commented 7 years ago

A few things:

This can be broken out into multiple tasks

Deon commented 7 years ago

User Table draft, based off of the current Mongoose Schema:

Also added a friends and friends request table. Please comment with suggested changes. I'll update this comment directly with changes.

CREATE TABLE users IF NOT EXISTS (
  id INT UNSIGNED AUTO_INCREMENT NOT NULL,
  password CHAR(60) NOT NULL,
  email VARCHAR(255) UNIQUE NOT NULL,
  username VARCHAR(255) UNIQUE,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
  password_reset_token BINARY(32),
  password_reset_token_expiry TIMESTAMP,
  PRIMARY KEY(id)
);
CREATE TABLE friends IF NOT EXISTS (
  requestor INT UNSIGNED NOT NULL,
  requestee INT UNSIGNED NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  accepted BOOLEAN NOT NULL,
  PRIMARY KEY(requestor, requestee),
  FOREIGN KEY(requestor) REFERENCES users(id),
  FOREIGN KEY(requestee) REFERENCES users(id)
);

CREATE INDEX friend_accepted ON friends(accepted);
Deon commented 7 years ago

Alternatively, we can merge friends/friend_requests into one and add a state enum (I think this is cleaner?).

Also, open to changes on friends key names.

yucombinator commented 7 years ago

Yeah we should merge them. Also do we need a requestor / requestee distinction? Or user1/user2 would be fine.

Deon commented 7 years ago

IMO yes b/c then we can distinguish between friend requests you've made, and requests others have made (at least it's more descriptive)

yucombinator commented 7 years ago

We can keep it that way (but I think in terms of UI we won't show anything differently once the request is accepted)

Deon commented 7 years ago

Agreed with the UI post-acceptance.

Deon commented 7 years ago

Updated DB design to reflect table merge, added index on acceptance.

yucombinator commented 7 years ago

👍