-
Notifications
You must be signed in to change notification settings - Fork 0
Database Schema
Joe Delaney edited this page May 6, 2022
·
10 revisions
column_name | data_type | details |
---|---|---|
id | integer | not null, primary key |
string | not null, indexed, unique | |
display_name | string | not null, indexed |
title | string | |
status | string | |
password_digest | string | not null |
session_token | string | not null, indexed, unique |
created_at | datetime | not null |
updated_at | datetime | not null |
-
display_name
is indexed to allow for quick search of users -
email
andsession_token
must be unique
- A user
has_many
created_channels
- A user
has_many
authored_messages
- A user
has_many
subscribed_channels
through
subscriptions
- A user
has_many
subscribed_groups
through
subscriptions
column_name | data_type | details |
---|---|---|
id | integer | not null, primary key |
creator_id | integer | not null, foreign key |
name | string | not null, indexed, unique |
topic | string | |
description | string | |
created_at | datetime | not null |
updated_at | datetime | not null |
-
creator_id
references the user who created this channel -
name
is indexed to allow for quicker search of channels
- A channel
belongs_to
thechannel_creator
- A channel
has_many
channel_members
through
subscriptions
- A channel
has_many
messages
column_name | data_type | details |
---|---|---|
id | integer | not null, primary key |
text | text | not null |
author_id | integer | not null, foreign key |
messagable_id | integer | not null, foreign key |
messagable_type | string | not null |
edited | boolean | default => false |
created_at | datetime | not null |
updated_at | datetime | not null |
-
author_id
refers to the user who created the message -
messagable_id
andmessagable_type
refers to where the message was added (channel or group). -
text
should not be null -
edited
will be used to flag if this message has been edited by the message's author
- Using Polymorphic associations, a message
belongs_to
either achannel
or agroup
- A message
belongs_to
anauthor
who can edit or delete that message
column_name | data_type | details |
---|---|---|
id | integer | not null, primary key |
hidden | boolean | default => false |
created_at | datetime | not null |
updated_at | datetime | not null |
- This table will be used for 2-person direct messages and larger group messages
-
hidden
will be used to display or hide the group from the user's sidebar
- A group
has_many
users
- A group
has_many
group_members
through
subscriptions
- A group
has_many
messages
column_name | data_type | details |
---|---|---|
id | integer | not null, primary key |
subscriber_id | integer | not null, foreign key |
subscribable_id | integer | not null, foreign key |
subscribable_type | string | not null |
created_at | datetime | not null |
updated_at | datetime | not null |
- Joins table for channels, groups and subscribers
-
subscriber_id
links to the users table -
subscribable_id
andsubscribable_type
link to the channels and groups tables - [
subscriber_id
,subscribable_id
,subscribable_type
] must be unique to ensure a user cannot subscribe to the same channel or group twice
- A subscription
belongs_to
asubscribed_channel
or asubscribed_group
- A subscription
belongs_to
asubscriber
column_name | data_type | details |
---|---|---|
id | integer | not null, primary key |
user_id | integer | not null, foreign key |
message_id | integer | not null, foreign key |
type | string | not null |
created_at | datetime | not null |
updated_at | datetime | not null |