项目资源数目迁移

This commit is contained in:
huang 2016-03-16 14:18:57 +08:00
parent 064dc81ed6
commit e8e9688644
2 changed files with 28 additions and 8 deletions

View File

@ -0,0 +1,19 @@
class AttachmentProjectCountUpdate < ActiveRecord::Migration
def up
Project.all.each do |project|
unless project.attachments.count.to_i == 0
attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{project.id} and container_type ='Project'").count
project_score = ProjectScore.where("project_id=?", project.id).first
if project_score.nil?
ProjectScore.create(:project_id => project.id, :attach_num => 0)
else
project_score.attach_num = attachment_count
project_score.save
end
end
end
end
def down
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20160225031230) do
ActiveRecord::Schema.define(:version => 20160316055201) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -432,9 +432,11 @@ ActiveRecord::Schema.define(:version => 20160225031230) do
t.integer "resource_num"
t.integer "journal_num"
t.integer "journal_reply_num"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "total_score"
t.integer "homework_journal_num", :default => 0
t.integer "news_num", :default => 0
end
create_table "course_groups", :force => true do |t|
@ -506,6 +508,7 @@ ActiveRecord::Schema.define(:version => 20160225031230) do
t.integer "is_excellent", :default => 0
t.integer "excellent_option", :default => 0
t.integer "is_copy", :default => 0
t.integer "visits", :default => 0
end
create_table "custom_fields", :force => true do |t|
@ -1282,6 +1285,7 @@ ActiveRecord::Schema.define(:version => 20160225031230) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "allow_guest_download", :default => true
t.integer "visits", :default => 0
end
create_table "phone_app_versions", :force => true do |t|
@ -1441,6 +1445,7 @@ ActiveRecord::Schema.define(:version => 20160225031230) do
t.integer "acts_count", :default => 0
t.integer "journals_count", :default => 0
t.integer "boards_reply_count", :default => 0
t.integer "visits", :default => 0
end
add_index "projects", ["lft"], :name => "index_projects_on_lft"
@ -1900,6 +1905,7 @@ ActiveRecord::Schema.define(:version => 20160225031230) do
t.string "mail_notification", :default => "", :null => false
t.string "salt", :limit => 64
t.integer "gid"
t.integer "visits", :default => 0
end
add_index "users", ["auth_source_id"], :name => "index_users_on_auth_source_id"
@ -2013,11 +2019,6 @@ ActiveRecord::Schema.define(:version => 20160225031230) do
add_index "wikis", ["project_id"], :name => "wikis_project_id"
create_table "wlcs", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "workflows", :force => true do |t|
t.integer "tracker_id", :default => 0, :null => false
t.integer "old_status_id", :default => 0, :null => false