建立所有数据库表

This commit is contained in:
tanhuazhe 2015-12-08 15:05:24 -06:00
parent 3674fe06cb
commit c3e9b917b0
10 changed files with 109 additions and 32 deletions

View File

@ -1,8 +1,20 @@
class CreateArticles < ActiveRecord::Migration class CreateArticles < ActiveRecord::Migration
def change def change
create_table :articles do |t| create_table :articles do |t|
t.integer :user_id
t.timestamps null: false t.string :title
t.string :tags
t.text :content
t.integer :view_count
t.integer :star_count
t.integer :comments_count
t.timestamps
end end
add_index :articles, :user_id
add_index :articles, :title
add_index :articles, :view_count
add_index :articles, :star_count
add_index :articles, :comments_count
add_index :articles, :created_at
end end
end end

View File

@ -1,8 +1,10 @@
class CreateCategories < ActiveRecord::Migration class CreateCategories < ActiveRecord::Migration
def change def change
create_table :categories do |t| create_table :categories do |t|
t.string :name
t.timestamps null: false t.integer :articles_count
t.timestamps
end end
add_index :categories, :articles_count
end end
end end

View File

@ -1,8 +1,10 @@
class CreateBlogInfos < ActiveRecord::Migration class CreateBlogInfos < ActiveRecord::Migration
def change def change
create_table :blog_infos do |t| create_table :blog_infos do |t|
t.string :name
t.timestamps null: false t.string :blog_title
t.string :email
t.text :description
end end
end end
end end

View File

@ -1,8 +1,10 @@
class CreateArticleStars < ActiveRecord::Migration class CreateArticleStars < ActiveRecord::Migration
def change def change
create_table :article_stars do |t| create_table :article_stars do |t|
t.integer :article_id
t.timestamps null: false t.integer :user_id
t.timestamps
end end
add_index :article_stars, [:article_id, :user_id]
end end
end end

View File

@ -1,8 +1,12 @@
class CreateArticleViews < ActiveRecord::Migration class CreateArticleViews < ActiveRecord::Migration
def change def change
create_table :article_views do |t| create_table :article_views do |t|
t.integer :article_id
t.timestamps null: false t.integer :user_id
t.string :ip
t.text :param_string
t.timestamps
end end
add_index :article_views, [:article_id, :ip, :created_at]
end end
end end

View File

@ -1,8 +1,12 @@
class CreateArticleComments < ActiveRecord::Migration class CreateArticleComments < ActiveRecord::Migration
def change def change
create_table :article_comments do |t| create_table :article_comments do |t|
t.integer :article_id
t.timestamps null: false t.integer :user_id
t.text :content
t.timestamps
end end
add_index :article_comments, :article_id
add_index :article_comments, :user_id
end end
end end

View File

@ -0,0 +1,5 @@
class AddSourceColumnToArticles < ActiveRecord::Migration
def change
add_column :articles, :source, :string
end
end

View File

@ -0,0 +1,5 @@
class AddCategoryIdColumnToArticles < ActiveRecord::Migration
def change
add_column :articles, :category_id, :integer
end
end

View File

@ -0,0 +1,7 @@
class AddNicknameAndAvatarColumnToUsers < ActiveRecord::Migration
def change
add_column :users, :nick_name, :string
add_column :users, :avatar, :string
add_index :users, :nick_name
end
end

View File

@ -11,38 +11,76 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160103065324) do ActiveRecord::Schema.define(version: 20151205174700) do
create_table "article_comments", force: :cascade do |t| create_table "article_comments", force: :cascade do |t|
t.datetime "created_at", null: false t.integer "article_id"
t.datetime "updated_at", null: false t.integer "user_id"
t.text "content"
t.datetime "created_at"
t.datetime "updated_at"
end end
add_index "article_comments", ["article_id"], name: "index_article_comments_on_article_id"
add_index "article_comments", ["user_id"], name: "index_article_comments_on_user_id"
create_table "article_stars", force: :cascade do |t| create_table "article_stars", force: :cascade do |t|
t.datetime "created_at", null: false t.integer "article_id"
t.datetime "updated_at", null: false t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end end
add_index "article_stars", ["article_id", "user_id"], name: "index_article_stars_on_article_id_and_user_id"
create_table "article_views", force: :cascade do |t| create_table "article_views", force: :cascade do |t|
t.datetime "created_at", null: false t.integer "article_id"
t.datetime "updated_at", null: false t.integer "user_id"
t.string "ip"
t.text "param_string"
t.datetime "created_at"
t.datetime "updated_at"
end end
add_index "article_views", ["article_id", "ip", "created_at"], name: "index_article_views_on_article_id_and_ip_and_created_at"
create_table "articles", force: :cascade do |t| create_table "articles", force: :cascade do |t|
t.datetime "created_at", null: false t.integer "user_id"
t.datetime "updated_at", null: false t.string "title"
t.string "tags"
t.text "content"
t.integer "view_count"
t.integer "star_count"
t.integer "comments_count"
t.datetime "created_at"
t.datetime "updated_at"
t.string "source"
t.integer "category_id"
end end
add_index "articles", ["comments_count"], name: "index_articles_on_comments_count"
add_index "articles", ["created_at"], name: "index_articles_on_created_at"
add_index "articles", ["star_count"], name: "index_articles_on_star_count"
add_index "articles", ["title"], name: "index_articles_on_title"
add_index "articles", ["user_id"], name: "index_articles_on_user_id"
add_index "articles", ["view_count"], name: "index_articles_on_view_count"
create_table "blog_infos", force: :cascade do |t| create_table "blog_infos", force: :cascade do |t|
t.datetime "created_at", null: false t.string "name"
t.datetime "updated_at", null: false t.string "blog_title"
t.string "email"
t.text "description"
end end
create_table "categories", force: :cascade do |t| create_table "categories", force: :cascade do |t|
t.datetime "created_at", null: false t.string "name"
t.datetime "updated_at", null: false t.integer "articles_count"
t.datetime "created_at"
t.datetime "updated_at"
end end
add_index "categories", ["articles_count"], name: "index_categories_on_articles_count"
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "username" t.string "username"
t.string "password_digest" t.string "password_digest"
@ -52,16 +90,12 @@ ActiveRecord::Schema.define(version: 20160103065324) do
t.datetime "last_reply_time" t.datetime "last_reply_time"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "nick_name"
t.string "avatar"
end end
add_index "users", ["email"], name: "index_users_on_email" add_index "users", ["email"], name: "index_users_on_email"
add_index "users", ["nick_name"], name: "index_users_on_nick_name"
add_index "users", ["username"], name: "index_users_on_username" add_index "users", ["username"], name: "index_users_on_username"
create_table "words", force: :cascade do |t|
t.string "name"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end end