Skip to content
Tim Bedford edited this page Nov 10, 2020 · 1 revision

Postgres Database Schema

users

column name data type null?
id integer no
username string no
email string no
password_digest string no
session_token string no
created_at datetime no
updated_at datetime no

primary key: id unique: username, email indexed: username, email


tracks

column name data type null?
id integer no
title integer no
uploader_id string no
play_count integer no
created_at datetime no
updated_at datetime no

primary key: id foreign keys: uploader id (users table)


follows

column name data type null?
id integer no
follower_id integer no
followee_id integer no
created_at datetime no
updated_at datetime no

primary key: id foreign keys: follower_id (users table), followee_id (users table) unique: [follower_id, followee_id] indexed: [follower_id, followee_id]


likes

column name data type null?
id integer no
user_id integer no
track_id integer no
created_at datetime no
updated_at datetime no

primary key: id foreign keys: user_id (users table), track_id (tracks table) unique: [:track_id, :user_id] indexed: [:track_id, :user_id]


reposts

column name data type null?
id integer no
user_id integer no
track_id integer no
created_at datetime no
updated_at datetime no

primary key: id foreign keys: user_id (users table), track_id (tracks table) unique: [:track_id, :user_id] indexed: [:track_id, :user_id]


plays

column name data type null?
id integer no
user_id integer no
track_id integer no
created_at datetime no
updated_at datetime no

primary key: id foreign keys: user_id (users table), track_id (tracks table) indexed: [:track_id, :user_id]


playlists

column name data type null?
id integer no
user_id integer no
created_at datetime no
updated_at datetime no

primary key: id foreign keys: user_id (users table)


playlists_tracks (Joins)

column name data type null?
id integer no
playlist_id integer no
track_id integer no
order integer no
created_at datetime no
updated_at datetime no

primary key: id foreign keys: playlist_id (playlists table), track_id (tracks table) indexed: [:track_id, :playlist_id] unique: [:track_id, :playlist_id], [:order, :playlist_id]

Clone this wiki locally