批判我的Stackoverflow架构。学习数据库设计

时间:2013-10-02 15:15:10

标签: 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

1 个答案:

答案 0 :(得分:3)

你在这里缺少的东西,如果继续,它绝对杀死你是索引