From c3e9b917b0267741316c01f2ba9af44056fa83df Mon Sep 17 00:00:00 2001 From: tanhuazhe Date: Tue, 8 Dec 2015 15:05:24 -0600 Subject: [PATCH] =?UTF-8?q?=E5=BB=BA=E7=AB=8B=E6=89=80=E6=9C=89=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20151204093252_create_articles.rb | 16 +++- .../20151204093310_create_categories.rb | 6 +- .../20151204093641_create_blog_infos.rb | 6 +- .../20151204093651_create_article_stars.rb | 6 +- .../20151204093656_create_article_views.rb | 8 +- .../20151204094413_create_article_comments.rb | 8 +- ...205125700_add_source_column_to_articles.rb | 5 ++ ...2200_add_category_id_column_to_articles.rb | 5 ++ ...add_nickname_and_avatar_column_to_users.rb | 7 ++ db/schema.rb | 74 ++++++++++++++----- 10 files changed, 109 insertions(+), 32 deletions(-) create mode 100644 db/migrate/20151205125700_add_source_column_to_articles.rb create mode 100644 db/migrate/20151205132200_add_category_id_column_to_articles.rb create mode 100644 db/migrate/20151205174700_add_nickname_and_avatar_column_to_users.rb diff --git a/db/migrate/20151204093252_create_articles.rb b/db/migrate/20151204093252_create_articles.rb index c4a8d5f..d302932 100644 --- a/db/migrate/20151204093252_create_articles.rb +++ b/db/migrate/20151204093252_create_articles.rb @@ -1,8 +1,20 @@ class CreateArticles < ActiveRecord::Migration def change create_table :articles do |t| - - t.timestamps null: false + t.integer :user_id + t.string :title + t.string :tags + t.text :content + t.integer :view_count + t.integer :star_count + t.integer :comments_count + t.timestamps 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 diff --git a/db/migrate/20151204093310_create_categories.rb b/db/migrate/20151204093310_create_categories.rb index 20f6143..5dcf448 100644 --- a/db/migrate/20151204093310_create_categories.rb +++ b/db/migrate/20151204093310_create_categories.rb @@ -1,8 +1,10 @@ class CreateCategories < ActiveRecord::Migration def change create_table :categories do |t| - - t.timestamps null: false + t.string :name + t.integer :articles_count + t.timestamps end + add_index :categories, :articles_count end end diff --git a/db/migrate/20151204093641_create_blog_infos.rb b/db/migrate/20151204093641_create_blog_infos.rb index 8fc7d52..f4d5842 100644 --- a/db/migrate/20151204093641_create_blog_infos.rb +++ b/db/migrate/20151204093641_create_blog_infos.rb @@ -1,8 +1,10 @@ class CreateBlogInfos < ActiveRecord::Migration def change create_table :blog_infos do |t| - - t.timestamps null: false + t.string :name + t.string :blog_title + t.string :email + t.text :description end end end diff --git a/db/migrate/20151204093651_create_article_stars.rb b/db/migrate/20151204093651_create_article_stars.rb index 81d2719..9513746 100644 --- a/db/migrate/20151204093651_create_article_stars.rb +++ b/db/migrate/20151204093651_create_article_stars.rb @@ -1,8 +1,10 @@ class CreateArticleStars < ActiveRecord::Migration def change create_table :article_stars do |t| - - t.timestamps null: false + t.integer :article_id + t.integer :user_id + t.timestamps end + add_index :article_stars, [:article_id, :user_id] end end diff --git a/db/migrate/20151204093656_create_article_views.rb b/db/migrate/20151204093656_create_article_views.rb index 5ff7e5f..a792e26 100644 --- a/db/migrate/20151204093656_create_article_views.rb +++ b/db/migrate/20151204093656_create_article_views.rb @@ -1,8 +1,12 @@ class CreateArticleViews < ActiveRecord::Migration def change create_table :article_views do |t| - - t.timestamps null: false + t.integer :article_id + t.integer :user_id + t.string :ip + t.text :param_string + t.timestamps end + add_index :article_views, [:article_id, :ip, :created_at] end end diff --git a/db/migrate/20151204094413_create_article_comments.rb b/db/migrate/20151204094413_create_article_comments.rb index a97fe90..d9ce91f 100644 --- a/db/migrate/20151204094413_create_article_comments.rb +++ b/db/migrate/20151204094413_create_article_comments.rb @@ -1,8 +1,12 @@ class CreateArticleComments < ActiveRecord::Migration def change create_table :article_comments do |t| - - t.timestamps null: false + t.integer :article_id + t.integer :user_id + t.text :content + t.timestamps end + add_index :article_comments, :article_id + add_index :article_comments, :user_id end end diff --git a/db/migrate/20151205125700_add_source_column_to_articles.rb b/db/migrate/20151205125700_add_source_column_to_articles.rb new file mode 100644 index 0000000..3a1ea2f --- /dev/null +++ b/db/migrate/20151205125700_add_source_column_to_articles.rb @@ -0,0 +1,5 @@ +class AddSourceColumnToArticles < ActiveRecord::Migration + def change + add_column :articles, :source, :string + end +end \ No newline at end of file diff --git a/db/migrate/20151205132200_add_category_id_column_to_articles.rb b/db/migrate/20151205132200_add_category_id_column_to_articles.rb new file mode 100644 index 0000000..e0644ab --- /dev/null +++ b/db/migrate/20151205132200_add_category_id_column_to_articles.rb @@ -0,0 +1,5 @@ +class AddCategoryIdColumnToArticles < ActiveRecord::Migration + def change + add_column :articles, :category_id, :integer + end +end \ No newline at end of file diff --git a/db/migrate/20151205174700_add_nickname_and_avatar_column_to_users.rb b/db/migrate/20151205174700_add_nickname_and_avatar_column_to_users.rb new file mode 100644 index 0000000..a988009 --- /dev/null +++ b/db/migrate/20151205174700_add_nickname_and_avatar_column_to_users.rb @@ -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 \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index c3cf5fa..7d1973d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,38 +11,76 @@ # # 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| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "article_id" + t.integer "user_id" + t.text "content" + t.datetime "created_at" + t.datetime "updated_at" 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| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "article_id" + t.integer "user_id" + t.datetime "created_at" + t.datetime "updated_at" 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| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "article_id" + t.integer "user_id" + t.string "ip" + t.text "param_string" + t.datetime "created_at" + t.datetime "updated_at" 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| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "user_id" + 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 + 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| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "name" + t.string "blog_title" + t.string "email" + t.text "description" end create_table "categories", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "name" + t.integer "articles_count" + t.datetime "created_at" + t.datetime "updated_at" end + add_index "categories", ["articles_count"], name: "index_categories_on_articles_count" + create_table "users", force: :cascade do |t| t.string "username" t.string "password_digest" @@ -52,16 +90,12 @@ ActiveRecord::Schema.define(version: 20160103065324) do t.datetime "last_reply_time" t.datetime "created_at" t.datetime "updated_at" + t.string "nick_name" + t.string "avatar" end 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" - 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