-
Notifications
You must be signed in to change notification settings - Fork 0
Schema
Kathryn Chu edited this page Mar 3, 2019
·
15 revisions
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
username |
string | not null, indexed, unique |
password_digest |
string | not null |
session_token |
string | not null, indexed, unique |
- index on
username
,unique: true
- index on
session_token
,unique: true
-
has_many
owned_playlists
-
has_many
album_saves
-
has_many
artist_saves
-
has_many
song_saves
-
has_many
playlist_saves
-
has_many
saved_playlists
throughplaylist_saves
(source:playlist
) -
has_many
saved_songs
throughsong_saves
(source:song
) -
has_many
saved_artists
throughartist_saves
(source:artist
) -
has_many
saved_albums
throughalbum_saves
(source:album
) -
has_many
owned_playlist_songs
throughowned_playlists
(source:playlist_songs
) -
has_many
followees
-
has_many
followers
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
name |
string | not null, indexed |
- index on
name
- has_many
albums
- has_many
songs
- has_many
artist_saves
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
title |
string | not null, indexed |
album_id |
integer | not null, indexed, foreign key |
artist_id |
integer | not null, indexed, foreign key |
duration |
integer | not null |
-
album_id
referencesalbums
-
artist_id
referencesartists
- index on
album_id
- index on
artist_id
- index on
title
- duration will be length of song in seconds
- belongs_to
album
- belongs_to
artist
- has_many
song_saves
- has_many
playlist_songs
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
title |
string | not null, indexed |
artist_id |
integer | not null, indexed, foreign key |
genre |
string |
-
artist_id
referencesartists
- index on
artist_id
- index on
title
- genre is optional for now
- belongs_to
artist
- has_many
songs
- has_many
album_saves
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
name |
string | not null, indexed |
owner_id |
integer | not null, indexed, foreign key |
-
owner_id
referencesusers
- index on
name
- index on
owner_id
- belongs_to
owner
- has_many
playlist_saves
- has_many
playlist_songs
- has_many
songs
throughplaylist_songs
(source:song
) - has_many
artists
throughsongs
(source:artist
) - has_many
albums
throughsongs
(source:album
) - has_many
playlist_followers
throughplaylist_saves
(source:user
)
The following tables are joins tables.
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
playlist_id |
integer | not null, indexed, foreign key |
song_id |
integer | not null, indexed, foreign key |
-
playlist_id
referencesplaylists
-
song_id
referencessong
- index on
playlist_id
- index on
song_id
- belongs_to
playlist
- belongs_to
song
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
playlist_id |
integer | not null, indexed, foreign key |
user_id |
integer | not null, indexed, foreign key |
-
playlist_id
referencesplaylists
-
user_id
referencesuser
- index on
playlist_id
- index on
user_id
- belongs_to
playlist
- belongs_to
user
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
song_id |
integer | not null, indexed, foreign key |
user_id |
integer | not null, indexed, foreign key |
-
song_id
referencessongs
-
user_id
referencesuser
- index on
song_id
- index on
user_id
- belongs_to
song
- belongs_to
user
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
artist_id |
integer | not null, indexed, foreign key |
user_id |
integer | not null, indexed, foreign key |
-
artist_id
referencesartists
-
user_id
referencesuser
- index on
artist_id
- index on
user_id
- belongs_to
artist
- belongs_to
user
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
album_id |
integer | not null, indexed, foreign key |
user_id |
integer | not null, indexed, foreign key |
-
album_id
referencesalbums
-
user_id
referencesuser
- index on
album_id
- index on
user_id
- belongs_to
album
- belongs_to
user
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
followee_id |
integer | not null, indexed, foreign key |
follower_id |
integer | not null, indexed, foreign key |
- index on
followee_id
- index on
follower_id
-
followee_id
referencesusers
-
follower_id
referencesusers
- Joins table: a user can have many followers and a user can follow many followees
- belongs_to
followee
- belongs_to
follower