Skip to content

Database Schema

ebaek edited this page Aug 9, 2019 · 18 revisions

USERS

Column Name Data Type Details
id integer not null, primary key
first_name string not null
last_name string not null
email string not null, indexed, unique
password_digest string not null
portfolio_value float not null
balance float 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
  • user has many watchlists and companies through watchlists
  • user has many transactions

COMPANIES

Column Name Data Type Details
id integer not null, primary key
ticker string not null, indexed, unique
created_at datetime not null
updated_at datetime not null
  • company has many many watchlists and watchers (users) through watchlists
  • company has many transactions

WATCHLISTS

column name data type details
id integer not null, primary key
user_id integer not null, indexed, foreign key, unique
ticker string not null, indexed, foreign key, unique
created_at datetime not null
updated_at datetime not null

TRANSACTIONS

column name data type details
id integer not null, primary key
user_id integer not null, indexed, foreign key
company_id integer not null, indexed, foreign key
purchase_price float not null
quantity integer not null
buy boolean not null
created_at datetime not null
updated_at datetime not null
  • transaction belongs to a user
  • transaction belongs to a company
Clone this wiki locally