Skip to content
aciffone23 edited this page May 26, 2023 · 5 revisions

Postgres Database Schema

users

column name data type details
id bigint not null, primary key
email string not null, indexed, unique
name string not null, indexed, unique
password_digest string not null
session_token string not null, indexed, unique
created_at datetime not null
updated_at datetime not null
  • index on username, unique: true
  • index on email, unique: true
  • index on session_token, unique: true
  • has_many reviews
  • has_one cart

cart

column name data type details
id integer not null, primary key
user_id integer not null, indexed, unique
product_id integer not null, indexed
quantity integer not null
created_at datetime not null
updated_at datetime not null
  • index on user_id
  • index on product_id
  • index on [:user_id, :product_id], unique: true
  • belongs_to user
  • has_many products

products

column name data type details
id integer not null, primary key
brand text not null
name string not null
description text not null
dimensions text
category string not null
price float not null
created_at datetime not null
updated_at datetime not null
  • has_many reviews

reviews

column name data type details
id integer not null, primary key
user_id integer not null, indexed, unique
product_id integer not null, indexed
title text not null
body text not null
rating float not null
created_at datetime not null
updated_at datetime not null
  • index on user_id
  • index on product_id
  • belongs_to user
  • belongs_to product

Clone this wiki locally