Skip to content

DB Schema

Alice Li edited this page Sep 3, 2022 · 6 revisions

Screen Shot 2022-09-03 at 12 51 16 AM

Users

Column Data Type Constraints
id Integer pk
username String not null
first_name String not null
last_name String not null
email String not null
points Integer default=0
password String not null
  • One-to-Many: 1 user can have many restaurants -
    restaurants = db.relationship('Restaurants',back_populates='user')
  • One-to-Many: 1 user can have many reservations -
    reservations = db.relationship('Reservation',back_populates='user')
  • One-to-Many: 1 user can have many reviews -
    reviews = db.relationship('Review',back_populates='user')
  • One-to-One: 1 user can have 1 favorite list -
    favorite = db.relationship('Favorite',back_populates='user')

Restaurants

Column Data Type Constraints
id Integer pk
name String not null
owner_id Integer not null
price_range Integer not null
adress String not null
city String not null
state String not null
zip_code Integer not null
description String
open_time Time not null
close_time Time not null
cuisine String not null
capacity Integer not null
availability Integer
cover String not null
  • ForeignKey - owner_id= db.Column(db.Integer, db.ForeignKey('users.id'),nullable=False)
  • Many-to-One: many restaurants can be owned by 1 user -
    user = db.relationship('User',back_populates='restaurants',foreign_key=[owner_id])
  • One-to-Many: 1 restaurant can have many reservations -
    reservations = db.relationship('Reservation',back_populates='restaurant')
  • Many-to-One: many restaurant belongs to 1 favorite list -
    favorite = db.relationship('Favorite',back_populates='restaurant',cascade='all,delete')
  • One-to-Many: 1 restaurant can have many reviews -
    reviews = db.relationship('Review',back_populates='restaurant',cascade='all,delete')
  • One restaurant can have many images -
    images = db.relationship('Image',back_populates='restaurant',cascade='all,delete')

Reservations

Column Data Type Constraints
id Integer pk
user_id Integer not null
restaurant_id Integer nullable
party_size Integer not null
date DateTime not null
reserve_time Time not null
occasion String
special_request String
created_at Time not null
  • restaurant_id is nullable -> when a restaurant is deleted, should still show the voided reservation for users
  • ForeignKey - user_id= db.Column(db.Integer, db.ForeignKey('users.id'),nullable=False)
  • ForeignKey - restaurant_id= db.Column(db.Integer, db.ForeignKey('restaurants.id'),nullable=False)
  • Many-to-One: many reservations belongs to 1 user -
    user = db.relationship('User',back_populates='reservations',cascade='all,delete')
  • Many-to-One: many reservations belongs to 1 restaurant -
    restaurant = db.relationship('Restaurant',back_populates='reservations',cascade='all,delete')

Reviews

Column Data Type Constraints
id Integer pk
user_id Integer not null
restaurant_id Integer not null
rating Integer not null
review_body String
created_at Time not null
updated_at Time not null
  • ForeignKey - user_id= db.Column(db.Integer, db.ForeignKey('users.id'),nullable=False)
  • ForeignKey - restaurant_id= db.Column(db.Integer, db.ForeignKey('restaurants.id'),nullable=False)
  • Many-to-One: many reviews belongs to 1 user -
    user = db.relationship('User',back_populates='reviews',cascade='all,delete')
  • Many-to-One: many reviews belongs to 1 restaurant -
    restaurant = db.relationship('Restaurant',back_populates='reviews',cascade='all,delete')
  • One-to-Many: 1 review can have many tags -
    tags = db.relationship('Tag',back_populates='review',cascade='all,delete')

Favorites

Column Data Type Constraints
id Integer pk
owner_id Integer not null
restaurant_id Integer not null
created_at DateTime not null
  • ForeignKey - user_id= db.Column(db.Integer, db.ForeignKey('users.id'),nullable=False)
  • ForeignKey - restaurant_id= db.Column(db.Integer, db.ForeignKey('restaurants.id'),nullable=False)
  • Many-to-One: many favorites belongs to 1 user -
    user = db.relationship('User',back_populates='favorites',cascade='all,delete')
  • One-to-Many: 1 favorite list can have many restaurants -
    restaurants = db.relationship('Restaurant',back_populates='favorite',cascade='all,delete')

Images

Column Data Type Constraints
id Integer pk
restaurant_id Integer not null
img text
  • ForeignKey - restaurant_id= db.Column(db.Integer, db.ForeignKey('restaurants.id'),nullable=False)
  • Many-to-One: many images belongs to 1 restaurant -
    restaurant = db.relationship('Restaurant',back_populates='images',cascade='all,delete')

Tags

Column Data Type Constraints
id Integer pk
category Integer
review_id Integer
  • ForeignKey - review_id= db.Column(db.Integer, db.ForeignKey('reviews.id'),nullable=False)
  • Many-to-One: many tags belongs to 1 review -
    review = db.relationship('Review',back_populates='tags',cascade='all,delete')
Clone this wiki locally