Skip to content

Database Schema

DavidWoolner edited this page Sep 3, 2021 · 22 revisions

Database Schema

Users

column name data type details
id integer not null, primary key
email string not null, indexed, unique
password_digest string not null
session_token string not null, indexed, unique
first_name string not null, indexed
last_name string not null, indexed
birthdate date not null, indexed
bio text
created_at datetime not null
updated_at datetime not null
  • index email and session_token, with constraints for uniqueness

Listings

column name data type details
id integer not null, primary key
title string not null, unique, indexed
description text not null
era_theme text not null
address string not null
longitude float not null
latitude float not null
num_bedrms integer not null
num_baths integer not null
price integer not null
clean_fee integer not null
service_fee integer not null
created_at datetime not null
updated_at datetime not null
  • title is unique and indexed

Bookings

column name data type details
id integer not null, primary key
listing_id integer not null, foreign key, indexed
booker_id integer not null, foreign key, indexed
check_in date not null
check_out date not null
guests integer not null
total_price float not null
created_at datetime not null
updated_at datetime not null
  • listing_id and booker_id are indexed foreign keys

Associations:

  • belongs_to listing, foreign key on listing_id points to listings
  • belongs_to booker, foreign key on booker_id points to users
  • has_one host, through listing source is owner
  • has_many reviews, foreign key is listing_id points to reviews

Reviews

column name data type details
id integer not null, primary key
listing_id integer not null, foreign keys, indexed
author_id integer not null, foreign keys, indexed
body text not null
rating integer not null
created_at datetime not null
updated_at datetime not null
  • listing_id and author_id are indexed foreign keys

Associations:

  • belongs_to author, foreign key on author_id points to user
  • belongs_to listing, foreign key on author_id points to user
Clone this wiki locally