建立所有数据库表
This commit is contained in:
parent
3674fe06cb
commit
c3e9b917b0
|
@ -1,8 +1,20 @@
|
|||
class CreateArticles < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :articles do |t|
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
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
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
class CreateCategories < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :categories do |t|
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
t.string :name
|
||||
t.integer :articles_count
|
||||
t.timestamps
|
||||
end
|
||||
add_index :categories, :articles_count
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
class CreateArticleStars < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :article_stars do |t|
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
t.integer :article_id
|
||||
t.integer :user_id
|
||||
t.timestamps
|
||||
end
|
||||
add_index :article_stars, [:article_id, :user_id]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
class CreateArticleViews < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :article_views do |t|
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
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
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
class CreateArticleComments < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :article_comments do |t|
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
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
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddSourceColumnToArticles < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :articles, :source, :string
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class AddCategoryIdColumnToArticles < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :articles, :category_id, :integer
|
||||
end
|
||||
end
|
|
@ -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
|
74
db/schema.rb
74
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
|
||||
|
|
Loading…
Reference in New Issue