Skip to content
Wayne Su edited this page Apr 24, 2020 · 9 revisions

Database Schema

users

User info for auth

column name datatype details
id integer not null, primary key
username string not null, indexed, unique
email string not null, indexed, unique
session_token string not null, indexed, unique
password_digest string not null
created_at datetime not null
updated_at datetime not null
  • has one avatar association from ActiveStorage

designs

Main CRUD feature, holding info of a single user design

column name datatype details
id integer not null, primary key
user_id integer not null, indexed, foreign key
creator_id integer not null, indexed, foreign key
folder_id integer not null, indexed, foreign key
title string not null
description string
public boolean not null
width float not null
height float not null
bgable_id integer not null, indexed, foreign key
bgable_type string not null, indexed
created_at datetime not null
updated_at datetime not null
  • creator_id references users
  • index on [title, user_id], unique: true
  • designs will reference both images and shapes via bgable_id and bgable_type
  • has one thumbnail association from ActiveStorage

elements

Polymorphic joins table that associates designs and elements, with shared info about the object

column name datatype details
id integer not null, primary key
design_id integer not null, indexed, foreign key
elementable_id integer not null, indexed, foreign key
elementable_type string not null, indexed
pos_x float not null
pos_y float not null
z_index integer not null
transparency float not null
created_at datetime not null
updated_at datetime not null
  • elements will reference backgrounds, shapes, text and images via elementable_id and elementable_type

shapes

More additional info of the element on your design that are shapes

column name datatype details
id integer not null, primary key
template_id integer not null, indexed, foreign key
width float not null
height float not null
color string
  • template_id references shape_templates

shape_templates

The circles, rectangles... all available shapes to choose from to add to your own design (Static, Not CRUD)

column name datatype details
id integer not null, primary key
type string not null
  • has one thumbnail association from ActiveStorage

text

More additional info of the element on your design that are text

column name datatype details
id integer not null, primary key
font_family string
font_size integer not null
font_weight integer not null
text text not null
color string

text_templates

The available text templates(preset) provided to you

column name datatype details
id integer not null, primary key
type string not null
sample_text string not null
  • has one thumbnail association from ActiveStorage

images

More additional info of the element on your design that are images(applies to both uploaded/stock images)

column name datatype details
id integer not null, primary key
imageable_id integer not null, indexed, foreign key
imageable_type string not null, indexed
width float not null
height float not null
crop_x float
crop_y float
  • images will reference both stock_photos and uploaded_images via imageable_id and imageable_type

stockphotos

Stores entries of stockphotos to choose from, not using Active Storage for image hostings with AWS

column name datatype details
id integer not null, primary key
title string not null, indexed
description string
thumb_url string not null
url string not null
width float not null
height float not null

uploaded_images

Stores additional info of the Active Storage managed image library

column name datatype details
id integer not null, primary key
title string not null, indexed
uploader_id integer not null, indexed, foreign key
width float not null
height float not null
created_at datetime not null
updated_at datetime not null
  • uploader_id references users
  • index on [title, uploader_id], unique: true
  • has one image association from ActiveStorage
  • has one thumbnail association from ActiveStorage

folders

Folder entries to organize designs

column name datatype details
id integer not null, primary key
owner_id integer not null, indexed, foreign key
name string not null, indexed
created_at datetime not null
updated_at datetime not null
  • owner_id references users
  • index on [name, owner_id], unique: true

tags

Design tags examples: poster, fb_cover, buisness_card... Stockphoto tags examples: nature, portrait, food. (Do I need to seperate design/stockphoto tags, would sql query times be different?)

column name datatype details
id integer not null, primary key
name string not null, indexed, unique
design boolean not null

tag_connections

Polymorphic joins table that associates tags and designs/stockphotos

column name datatype details
id integer not null, primary key
tag_id integer not null, indexed, foreign key
taggable_id integer not null, indexed, foreign key
taggable_type string not null, indexed
  • index on [tag_id, taggable_id, taggable_type], unique: true
  • tag_connections will reference both designs and stockphotos via taggable_id and taggable_type

likes

Polymorphic joins table that associates users and designs/stockphotos

column name datatype details
id integer not null, primary key
user_id integer not null, indexed, foreign key
likeable_id integer not null, indexed, foreign key
likeable_type string not null, indexed
created_at datetime not null
updated_at datetime not null
  • likes will reference both stock_photos and designs via likeable_id and likeable_type
  • index on [user_id, likeable_id, likeable_type], unique: true

TBD

undo history(should be in front end?), how would I associate Active Storage