-
Notifications
You must be signed in to change notification settings - Fork 0
Database Schema
Schema for PostgresQL using Sequelize ORM
This project has 6 tables: Users, Laughs, LaughBoxes, LaughBoxLaughs, Ratings, and Reviews
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
username |
string | not null, indexed, unique |
email |
string | not null, indexed, unique |
hashedPassword |
string | not null |
createdAt |
datetime | not null |
updatedAt |
datetime | not null |
- unique index on
username - unique index on
email - Sequelize
hasManyLaughsassociation - Sequelize
hasManyLaughBoxesassociation - Sequelize
hasManyRatingsassociation - Sequelize
hasManyReviewsassociation
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
body |
string | not null, indexed |
userId |
integer | not null, indexed, foreign key |
createdAt |
datetime | not null |
updatedAt |
datetime | not null |
-
userIdreferencesUserstable id - index on
userId - unique index on
[body, authorUserId] - Sequelize
belongsToUsersassociation - Sequelize
hasManyRatingsassociation - Sequelize
hasManyReviewsassociation - Sequelize
hasManyLaughBoxesassociation - Sequelize
belongsToManyLaughBoxLaughsthroughLaughBoxLaughsasLaughsInLaughBoxassociation
unique index on
[body, userId]will only allow a laugh to be created by the same user once.
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
name |
string | not null, indexed, unique |
userId |
integer | not null, indexed, foreignKey |
createdAt |
datetime | not null |
updatedAt |
datetime | not null |
- unique primary key on
id - unique index on
[name, userId] - foreign key on
userIdconnects to Users table on id - name is the name of the LaughBox
- Sequelize
hasManyLaughBoxLaughsassociation - Sequelize
belongsToUsersassociation - Sequelize
belongsToManyLaughsthroughLaughBoxLaughsasLaughsInLaughBoxassociation
unique index on
[name, userId]will only allow a laughbox of a particular name to be created by the same user once.
We don't need a separate index for
nameoruserIdbecause the index on[name, userId]adds it for us.
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
laughId |
integer | not null, indexed, foreignKey |
laughBoxId |
integer | not null, indexed, foreignKey |
createdAt |
datetime | not null |
updatedAt |
datetime | not null |
- unique primary key on
id - foreign key on
laughIdconnects to Laughs table on id - foreign key on
laughBoxIdconnects to LaughBoxes table on id - unique index on
[laughId, laughBoxId] - Sequelize
belongsToLaughs - Sequelize
belongsToLaughBoxes
unique index on
[laughId, laughBoxId]will only allow a laugh to be added to a laughbox once.
We don't need a separate index for
laughIdorlaughBoxIdbecause the index on[laughId, laughBoxId]adds it for us.
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
bows |
boolean | not null |
lols |
integer | not null |
userId |
integer | not null, indexed, foreign key |
laughId |
integer | not null, indexed, foreign key |
createdAt |
datetime | not null |
updatedAt |
datetime | not null |
-
userIdreferencesUserstable -
laughIdreferencesLaughstable - unique index on
[laughId, userId] - 'lols' is 1 to 5
- Sequelize
belongsToUsersassociation - Sequelize
belongsToLaughsassociation
unique index on
[laughId, userId]will only not allow a laugh to be liked by the same user once.
We don't need a separate index for
laughIdoruserIdbecause the index on[laughId, userId]adds it for us.
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
body |
string | not null |
userId |
integer | not null, foreignKey |
laughId |
integer | not null, foreignKey |
createdAt |
datetime | not null |
updatedAt |
datetime | not null |
- unique primary key on
id - name is the name of the LaughBox
- unique index on
[laughId, userId] - foreign key on
userIdconnects to Users table on id - foreign key on
laughIdconnects to Laughs table on id - Sequelize
belongsToUsersassociation - Sequelize
belongsToLaughsassociation