mysql - 批评我的 Stackoverflow 架构。学习数据库设计

标签 mysql ruby-on-rails database-design

<分区>

您将如何更改以下试图复制 Stackoverflow 功能的模式:

create_table "questions", :force => true do |t|
    t.text      "question",         :null => false
    t.text      "description",  :null => false
    t.integer       "up_votes",         :null => false, :default => 0
    t.integer       "down_votes",       :null => false, :default => 0
  t.timestamps
end

create_table "answers", :force => true do |t|
    t.integer       "question_id",  :null => false
    t.text      "answer",               :null => false
    t.integer       "up_votes",         :null => false, :default => 0
    t.integer       "down_votes",       :null => false, :default => 0
  t.timestamps
end

create_table "question_comments", :force => true do |t|
    t.integer   "question_id",  :null => false
    t.text      "comment",          :null => false
  t.timestamps
end

create_table "answer_comments", :force => true do |t|
    t.integer   "answer_id",    :null => false
    t.text      "comment",      :null => false
  t.timestamps
end

create_table "tags", :force => true do |t|
    t.string        "tag",  :null => false, :limit => 100
  t.timestamps
end
add_index "tags", ["tag"], :name => "tag_UNIQUE", :unique => true

create_table "question_tags", :force => true do |t|
  t.integer     "question_id",  :null => false
  t.integer     "tag_id",               :null => false
  t.timestamps
end

create_table "users", :force => true do |t|
    t.string        "first_name",   :limit => 45,       :null => false
    t.string        "last_name",    :limit => 45,       :null => false
    t.string        "email",            :limit => 100,  :null => false
    t.string        "password",                                     :null => false
    t.string        "salt",                                             :null => false
  t.timestamps
end

create_table "user_votes", :force => true do |t|
    t.integer       "user_id",  :null => false
    t.integer       "question_id"
    t.integer       "answer_id"
    t.boolean       "is_positive_vote"
    t.timestamps
end

create_table "user_favorites", :force => true do |t|
    t.integer       "user_id",  :null => false
    t.integer       "question_id"
    t.integer       "answer_id"
    t.timestamps
end

create_table "question_flags", :force => true do |t|
    t.integer       "user_id",  :null => false
    t.integer       "question_id"
    t.timestamps
end

create_table "answer_flags", :force => true do |t|
    t.integer       "user_id",  :null => false
    t.integer       "question_id"
    t.timestamps
end

create_table "related_questions", :force => true do |t|
    t.integer       "question_id",                  :null => false
    t.integer       "related_question_id",  :null => false
    t.timestamps
end

最佳答案

您在这里缺少的是索引,如果您继续,它绝对杀死您。

关于mysql - 批评我的 Stackoverflow 架构。学习数据库设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19140413/

相关文章:

MySQL : trigger to capitalize first letter of each word

mysql - 在部门表中插入值

php - 存储过程在下一个查询中导致 "Commands out of sync"

ruby-on-rails - Guard 看不到文件更新

mysql - 在设计数据库时,通常是删除实际记录,还是切换 "the undisplay flag"?

php - 电子商务,存储订购的产品和产品选项

mysql - 如何进行 mysql 查询并将结果打印在 cakephp 页面上

ruby-on-rails - 工厂女孩 : Creating associated records

mysql - rails : how to select_rows with fields names (mysql)

mysql - 是否可以向 mysql 中的字段添加额外的列?