LoginSignup
0
0

More than 3 years have passed since last update.

DB設計の備忘録

Posted at

個人アプリの開発に伴いDB設計した。
アプリはチャット型の推理ゲームなのでこのように設計してみた。

usersテーブル

Column Type Options
email string null: false
password string null: false
username string null: false
image string

Association

  • has_many :messages
  • has_many :groups, through: :group_users
  • has_many :group_users

groups_usersテーブル

Column Type Options
user_id integer null: false, foreign_key: true
group_id integer null: false, foreign_key: true

Association

  • belongs_to :group
  • belongs_to :user

groupテーブル

Column Type Options
title string null: false

Association

  • has_many :user, through: :group_users
  • has_many :messages -has_many :group_users

messageテーブル

Column Type Options
image string
text text
user_id integer null: false, foreign_key: true
group_id integer null: false, foreign_key: true

Association

  • belongs_to :user
  • belongs_to :group

positionテーブル

Column Type Options
master string null: false, foreign_key: true
insider string null: false, foreign_key: true
normal string null: false, foreign_key: true
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0