Skip to content
Yan Rivera edited this page Oct 26, 2022 · 25 revisions

users

column name data type details
id integer not null, primary key
username string not null, indexed, unique
email string not null, indexed, unique
password_digest 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 messages
  • has_many workspace_subscriptions
  • has_many direct_message_subscriptions
  • has_many channel_subscriptions
  • has_many conversations, through: direct_message_subscriptions
  • has_many workspaces, through: workspace_subscriptions
  • has_many channels, through: channel_subscriptions

workspaces

column name data type details
id integer not null, primary key
name string not null, indexed, unique
owner_id bigint not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • index on name, unique: true
  • index on owner_id
  • owner_id references users
  • has_many users, through: workspace_subscriptions
  • has_many channels
  • has_many direct_messages
  • belongs_to owner

workspace_subscriptions

column name data type details
id integer not null, primary key
user_id bigint not null, indexed, foreign key
workspace_id bigint not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • index on user_id
  • index on workspace_id
  • user_id references users
  • workspace_id references workspaces
  • belongs_to user
  • belongs_to workspace

messages

column name data type details
id integer not null, primary key
content text not null, indexed, unique
author_id bigint not null, indexed, foreign key
messageable_id bigint indexed
messageable_type string indexed
created_at datetime not null
updated_at datetime not null
  • index on content, unique: true
  • index on author_id
  • index on messageable_id
  • index on messageable_type
  • author_id references users
  • belongs_to author
  • belongs_to messageable, polymorphic: true

direct_messages

column name data type details
id integer not null, primary key
workspace_id bigint not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • index on workspace_id
  • workspace_id references workspaces
  • belongs_to workspace
  • has_many user_direct_messages
  • has_many messages, as messageable
  • has_many users, through: direct_message_subscriptions

direct_message_subscriptions

column name data type details
id integer not null, primary key
user_id bigint not null, indexed, foreign key
direct_message_id bigint not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • index on user_id
  • index on direct_message_id
  • user_id references users
  • direct_message_id references direct_messages
  • belongs_to user
  • belongs_to direct_messages

channels

column name data type details
id integer not null, primary key
name text not null, indexed, unique
workspace_id bigint not null, indexed, foreign key
owner_id bigint not null, indexed, foreign key
description string
created_at datetime not null
updated_at datetime not null
  • index on name, unique: true
  • index on workspace_id
  • workspace_id references workspaces
  • has_many messages, as messageable
  • has_many users, through: channel_subscriptions
  • belongs_to workspace
  • belongs_to owner

channel_subscriptions

column name data type details
id integer not null, primary key
user_id bigint not null, indexed, foreign key
channel_id bigint not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • index on user_id
  • index on channel_id
  • user_id references users
  • channel_id references channels
  • belongs_to user
  • belongs_to channel