Skip to content
Vincent Shuali edited this page May 12, 2023 · 34 revisions

User

Column Name Data Type Details
id bigint primary key
username string not null, unique
password_digest varchar(255) not null
last_login datetime not null
created_at datetime not null
updated_at datetime not null

has many:

  • members (a user may become more than one member to be in more than one club)

Club

Column Name Data Type Details
id bigint primary key
name string not null, unique
location string not null
join_code varchar(6) not null
created_at datetime not null
updated_at datetime not null

To create a member and join a club, you must enter the current join code, which owner can periodically change for security reasons.

indexes:

  • name

has many:

  • members
  • lunches

Members table

Column Name Data Type Details
id bigint primary key
name string not null, index
member_info member_type not null
email string not null, unique
club_id bigint foreign key
user_id bigint foreign key, unique
created_at datetime not null
updated_at datetime not null

member_type is an ENUM that can be either 'banned', 'regular', or 'admin'.

indexes

  • index on name
  • index on user_id, unique: true

belongs to:

  • club (club_id)
  • user (user_id)

has many:

  • votes
  • lunches

has many through:

  • poll_options through votes

Uniqueness constraint of email in scope of club_id

Restaurant

Column Name Data Type Details
id bigint primary key
name string not null, index
address string not null
created_at datetime not null
updated_at datetime not null

has many:

  • lunches

Uniqueness constraint on (name, address)

Lunch

Column Name Data Type Details
id bigint primary key
club_id bigint foreign key
restaurant_id bigint foreign key
name string not null, index
lunch_date datetime not null, index
poll_open_date datetime not null
poll_close_date datetime not null

belongs to:

  • club
  • restaurant (this can be optional, until poll closes)

has many:

  • poll_options

has many through:

  • votes (votes through poll_options)
  • voters (members through votes through poll_options)

Notes: Open date can default to time poll was created. Poll close date can default to 24 hours before lunch date. Both of these can be set on the frontend restaurant_id can be optional, until poll closes

We may want to limit when the organizer can change the date of a poll, to either a time limit or before anyone has cast a vote.

Poll Options Table

Column Name Data Type Details
id bigint primary key
lunch_id bigint foreign key
restaurant_id bigint foreign key

belongs to:

  • lunch
  • restaurant

has many:

  • votes

Votes

Column Name Data Type Details
id bigint primary key
member_id bigint foreign key
lunch_id bigint foreign key
poll_option_id bigint foreign key

indexes:

  • member_id
  • lunch_id
  • poll_option_id

Uniqueness constraint on (member_id, lunch_id) to prevent member from voting in the same lunch twice

belongs to:

  • member
  • lunch
  • poll_option