Skip to content
Rupa Dhillon edited this page Aug 11, 2019 · 2 revisions

Bench BnB Schema

All tables include date-time columns for created_at and updated_at, which are not shown below. Active Storage tables are not listed below.

Benches

Column Data Type Required Default
description string yes N/A
lat float yes N/A
lng float yes N/A
seating integer yes N/A
num_reviews integer no 0
review_total integer no 0

Reviews

Column Data Type Required Default
user_id integer yes N/A
bench_id integer yes N/A
rating integer yes N/A
comment string yes N/A

Users

Column Data Type Required Default
username string yes N/A
password_digest string yes N/A
session_token string yes N/A

Record Constraints

Benches: No constraints.

Reviews: A user may only review a bench once.

Users: Session token and username must be unique.

Column Caching

The benches table manually caches the number of total reviews and the total review score per bench. These values are updated any time a review is submitted. If a review is destroyed (only doable via backend currently), the bench table will be updated via the Review model's before_destroy action.

If users are allowed to edit their review ratings, necessary methods will need to be added either to the model or the controller.

Clone this wiki locally