Skip to content

Commit

Permalink
Update DatabaseDesign.md
Browse files Browse the repository at this point in the history
  • Loading branch information
karenaliang authored Oct 10, 2024
1 parent 3e9aff0 commit 4d5364b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions doc/DatabaseDesign.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
## ER Diagram
![image](https://github.com/user-attachments/assets/7bacff2e-887d-4cc5-a653-42e2ebb8681c)

States was modeled as a separate entity instead of within the recreation entity to reduce redundancy, since many tuples would have the same state in the recreation entity. Similarly, the favorites entity was modeled separate from the users entity to avoid redundancy with identical favorited recreation among several users.
## Assumptions
Users is modeled as an entity to store all user information, including username and email, with username (which will require distinctness) as the primary key to uniquely identify each individual.

Recreation is modeled as entity to store all recreational locations with RecName as a primary key to identify each recreation uniquely. StateName is set as a foreign key to reference the States relation.

States was modeled as a separate entity instead of within the recreation entity to reduce redundancy, since many tuples would have the same state in the recreation entity, with StateName as the primary key to uniquely identify states. Similarly, the favorites entity was modeled separate from the users entity to avoid redundancy with identical favorited recreation among several users. Favorites is modeled as an entity to store a bank of favorited recreation users want to save for later, with Username as a primary key to uniquely identify each favorite. Username and RecName is set as foreign keys to reference the Users and Recreation entities, respectively.

Discounts is modeled as an entity to store all possible discounts, with DiscountId as the primary key to uniquely identify each discount and RecName as a foreign key to reference the Recreation relation.

Comments is modeled as entity to store all user comments with CommentId as a primary key to identify each comment uniquely. Username and RecName is set as foreign keys to reference the Users and Recreation entities, respectively.

---------------

Discounts and recreation have a many-to-many relation, since a feature such as a veteran discount can be applicable to more than one recreation and vice versa - one recreation can have multiple discounts such as having both a veteran discount and a student discount. One recreation is allowed exactly one state, since there is only one location, though one state (location) can have many recreational activities.

One comment is only allowed one recreation, since a user’s message cannot be applied to multiple recreational activities; this can also minimize fake reviews. One recreation is allowed 0 or more comments, to allow for a variety of user comments. Similarly, one user can leave multiple comments for various recreation but one comment can only be contributed by one user.


One favorite by a user can only have one recreation (there can be multiple rows with same user but not one row with multiple recreation), while one recreation can be favorited by multiple users. With similar logic, for the “likes” relation - one user can have multiple favorites, but one favorite can only have exactly one user.

## Normalization - 3NF Decomposition
Expand Down Expand Up @@ -127,7 +137,7 @@ Recreation (
)
States (
StateName: VARCHAR(255) [PK],
StateName: VARCHAR(2) [PK],
CityCount: INT,
Region: VARCHAR(255),
TotalArea: REAL,
Expand Down

0 comments on commit 4d5364b

Please sign in to comment.