Skip to content

Database Schema

aguamenti edited this page Aug 18, 2018 · 23 revisions

all tables

  • users
  • permissions (joins)
  • channels
  • memberships (joins)
  • direct_messages

users

Column Name Data Type Details
id integer not null, primary key
email string not null, indexed, unique
display_name string not null
password_digest string not null
session_token string not null, indexed, unique
  • index on email, unique: true
  • index on session_token, unique: true
  • AWS will host profile pictures, so img_url unnecessary

permissions (joins)

Column Name Data Type Details
id integer not null, primary key
user_id integer not null
channel_id integer not null
  • user_id references users (belongs_to :user)
  • channel_id references channels (belongs_to :channel)
  • index on :channel_id
  • index on [:user_id, :channel_id], unique: true

channels

Column Name Data Type Details
id integer not null, primary key
title string not null
private boolean not null
is_dm boolean not null
  • has_many :permissions
  • has_many :permitted_users, through: permissions, source: user
  • has_many :messages, as: :messageable

messages

Column Name Data Type Details
id integer not null, primary key
body text not null
author_id integer not null, indexed, foreign key
messageable_type string not null
messageable_id integer not null, foreign key
  • author_id references users (belongs_to :user)
  • belongs_to messageable, polymorphic: true
    • messageable_type is "channel"
    • messageable_id references a channel

included in all tables

Column Name Data Type Details
created_at datetime not null
updated_at datetime not null
Clone this wiki locally