Skip to content

Database Schema

Kevin Bartolome edited this page Apr 28, 2022 · 18 revisions

Schema of the PostgreSQL database

Associations

+ Users Table
  - Many to Many: User belongsToMany Image (fk: userId // through: "Favorite" // otherKey: imageId)
  - One to Many: User hasMany Image (fk: userId)
  - One to Many: User hasMany Favorite (fk: userId)
  - One to Many: User hasMany Profile (fk: userId)
  - One to Many: User hasMany Comment (fk: userId)
  - One to Many: User hasMany Comment (fk: uploaderId)

+ Images Table
  - Many to Many: Image belongsToMany User (fk: imageId // through: "Favorite" // otherKey: userId)
  - Many to One: Image belongsTo User (fk: userId)
  - One to Many: Image hasMany Favorite (fk: imageId)

+ Comments Table
  - Many to One: Comment belongsTo User (fk: userId)
  - Many to One: Comment belongsTo User (fk: uploaderId)

+ Profile Table
  - Many to One: Profile belongsTo User (fk: userId)

- Favorites Table
  - Join Table for User/Images
  - Many to Many: Favorite belongsTo User (fk: userId)
  - Many to Many: Favorite belongsTo Image (fk: imageId)

Users table

column names data type details
id integer PK, not null
username string(3, 256) unique, not null
email string(3, 30) unique, not null
hashedPassword string.binary unique, not null
  • username, unique: true
  • email, unique: true

Images table

column names data type details
id integer PK, not null
userId integer foreign key
imageURL string not null
tags array defaultValue = []
favoritedCount integer not null, defaultValue = 0
  • userId references Users table

Comments table

column names data type details
id integer PK, not null
userId integer foreign key
uploaderId integer foreign key
commentText text not null
  • userId references Users table
  • uploaderId references Users table

Profiles table

column names data type details
id integer PK, not null
userId integer foreign key
fullName string not null
location string not null
avatar string defaultValue = "default-avatar.jpg"
biography text not null
  • userId references Users table

Favorites table

column names data type details
id integer PK, not null
userId integer foreign key
imageId integer foreign key
  • userId references Users table
  • imageId references Images table
Clone this wiki locally