Skip to content
HammadKhalid101 edited this page Mar 22, 2021 · 22 revisions

Postgres Database Schema

users

Column Name Data Type Details
id integer not null, primary key
first_name string not null
last_name string not null
username string not null, indexed, unique
email string not null, indexed, unique
password_digest string not null
session_token string not null, indexed, unique
buying_power integer
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 :assets association with assets table on user_id
  • has_many :owned_stocks through assets
  • has_many :watchlists association with wacthlists table on user_id

stocks

Column Name Data Type Details
id integer not null, primary key
name string not null, indexed, unique
tikr string not null, indexed, unique
last_price decimal not null
percentage_change decimal not null
created_at datetime not null
updated_at datetime not null
  • index on name, unique: true
  • index on tikr, unique: true
  • has_many :assets association with assets table on stock_id
  • has_many :owners through assets source owner

assets

Column Name Data Type Details
id integer not null, primary key
user_id integer not null
stock_id integer not null
quantity integer not null
avg_price integer not null
created_at datetime not null
updated_at datetime not null
  • user_id references users
  • stock_id references stocks
  • belongs_to :owner association with users table on user_id
  • belongs_to :stocks association with stocks table on stock_id

watchlists

Column Name Data Type Details
id integer not null, primary key
title string not null
user_id integer not null
created_at datetime not null
updated_at datetime not null
  • user_id references users
  • belongs_to :user association with users table on user_id
  • has_many :watchlists association with wacthlist_joins on watchlist_id
  • has_many :stocks through watchlists

watchlist_joins

Column Name Data Type Details
id integer not null, primary key
watchlist_id integer not null
stock_id integer not null
created_at datetime not null
updated_at datetime not null
  • watchlist_id references watchlist
  • stock_id references stocks

Clone this wiki locally