Skip to content

Database Schema

taisiat edited this page May 4, 2023 · 31 revisions

Postgres Database Schema

users

column name date type details
id bigint not null, primary key
first_name string not null
last_name string not null
approved_to_drive boolean not null, default:true
is_superhost boolean not null, default:false
is_clean_certified boolean not null, default:false
email string not null, indexed, unique
phone_number string
password_digest string not null
session_token string not null, indexed, unique
created_at datetime not null
updated_at datetime not null
  • index on email, unique: true
  • index on session_token, unique: true
  • has_many trips
  • has_many favorites
  • has_many reviews
  • has_many reviews_for_own_cars
  • has_many cars
  • has_one_attached photo

cars

column name date type details
id bigint not null, primary key
make string not null
model string not null
year integer not null
mpg integer not null
doors_count integer not null
seats_count integer not null
category string not null
automatic boolean not null, default:true
description text not null
guidelines text not null
daily_rate integer not null
location text array:true
active boolean not null, default:true
host_id bigint not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • host_id references users
  • index on host_id
  • belongs_to host
  • has_many trips
  • has_many reviews
  • has_many_attached photos

trips

column name date type details
id bigint not null, primary key
start_date datetime not null
end_date datetime not null
protection_plan string not null
driver_id bigint not null, indexed, foreign key
car_id bigint not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • driver_id references users
  • index on driver_id
  • belongs_to driver
  • car_id references cars
  • index on car_id
  • belongs_to car

reviews

column name date type details
id bigint not null, primary key
cleanliness_rating integer not null
maintenance_rating integer not null
communication_rating integer not null
convenience_rating integer not null
accuracy_rating integer not null
comment text not null
driver_id bigint not null, indexed, foreign key
car_id bigint not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • driver_id references users
  • index on driver_id
  • belongs_to driver
  • car_id references cars
  • index on car_id
  • belongs_to car
  • car_id unique within scope of driver_id

car_favorites (joins table)

column name date type details
id bigint not null, primary key
driver_id bigint not null, indexed, foreign key
car_id bigint not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • driver_id references users
  • index on driver_id
  • belongs_to driver
  • car_id references cars
  • index on car_id
  • belongs_to car
  • car_id unique within scope of driver_id

Clone this wiki locally