Skip to content
Timothy Chang edited this page Feb 3, 2023 · 28 revisions

Postgres Database Schema

users

column name data type details
id bigint not null, primary key
username string not null, indexed, unique
password_digest string not null
email string not null, indexed, unique
name string not null
birth_date 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 songs
  • has_many likes
  • has_many playlists

songs

column name data type details
id bigint not null, primary key
album_id integer foreign key
artist_id integer not null, indexed, foreign key
title string not null, indexed
created_at datetime not null
updated_at datetime not null
  • index on title
  • index on artist_id
  • artist_id references artists
  • album_id references albums
  • has_many likes
  • belongs_to user
  • belongs_to playlist
  • belongs_to artist
  • belongs_to album

playlists

column name data type details
id bigint not null, primary key
author_id integer not null, indexed, foreign key
title string not null, indexed
public boolean not null
created_at datetime not null
updated_at datetime not null
  • index on author_id
  • index on title
  • author_id references artists
  • belongs_to user
  • has_many songs
  • has_many likes

likes

column name data type details
id bigint not null, primary key
liker_id integer not null, foreign key, indexed
media_id integer not null, foreign key, indexed
media_type string not null
created_at datetime not null
updated_at datetime not null
  • index on liker_id
  • index on media_id
  • [:liker_id, :media_id] unique: true
  • liker_id references users
  • media_id references [songs, playlists, albums]
  • belongs_to user
  • belongs_to playlist
  • belongs_to song
  • belongs_to album

artists

column name data type details
id bigint not null, primary key
name string not null, indexed
description text not null
created_at datetime not null
updated_at datetime not null
  • index on name
  • has_many songs
  • has_many albums

albums

column name data type details
id bigint not null, primary key
title string not null, indexed
artist_id integer not null, foreign key, indexed
published_date string not null
created_at datetime not null
updated_at datetime not null
  • index on title
  • index on artist_id, unique: true
  • artist_id references artists
  • belongs_to artist
  • has_many likes
  • has_many songs

Clone this wiki locally