提交新迁移

This commit is contained in:
huang 2016-01-14 11:37:10 +08:00
parent 70cd068ea8
commit e808f0bc61
4 changed files with 80 additions and 2034 deletions

View File

@ -155,7 +155,7 @@ class Project < ActiveRecord::Base
# 创建project之后默认创建一个board之后的board去掉了board的概念
after_create :create_board_sync,:acts_as_forge_activities,:create_project_ealasticsearch_index
before_destroy :delete_all_members,:delete_project_ealasticsearch_index
# after_update :update_project_ealasticsearch_index
after_update :update_project_ealasticsearch_index
def remove_references_before_destroy
return if self.id.nil?
Watcher.delete_all ['watchable_id = ?', id]
@ -1223,26 +1223,27 @@ class Project < ActiveRecord::Base
self.__elasticsearch__.index_document
end
end
# def update_project_ealasticsearch_index
# if self.is_public #如果是初次更新成为公开的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性
# begin
# self.__elasticsearch__.update_document
# rescue => e
# self.__elasticsearch__.index_document
# end
# else #如果是更新成为私有的,那么索引就要被删除
# begin
# self.__elasticsearch__.delete_document
# rescue => e
#
# end
# end
# end
def update_project_ealasticsearch_index
if self.is_public #如果是初次更新成为公开的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性
begin
self.__elasticsearch__.update_document
rescue => e
self.__elasticsearch__.index_document
end
else #如果是更新成为私有的,那么索引就要被删除
begin
self.__elasticsearch__.delete_document
rescue => e
end
end
end
def delete_project_ealasticsearch_index
begin
self.__elasticsearch__.delete_document
rescue => e
end
end

View File

@ -0,0 +1,7 @@
class AddBoardNumToProjectScore < ActiveRecord::Migration
def change
add_column :project_scores, :board_num, :integer, :default => false
add_column :project_scores, :act_num, :integer, :default => false
add_column :project_scores, :attach_num, :integer, :default => false
end
end

View File

@ -0,0 +1,51 @@
class UpdateProjectScore < ActiveRecord::Migration
def up
project_count = Project.all.count / 30 + 2
transaction do
for i in 1 ... project_count do i
Project.page(i).per(30).each do |project|
puts project.id
unless project.project_score.nil?
# update boards
unless project.boards.first.nil?
boards_count = project.boards.first.topics.count
project.project_score.update_attribute(:board_num, boards_count)
end
# update boards reply
unless project.boards.first.nil?
messages_count = Message.where("board_id =? and parent_id is not ?", project.boards.first.id, nil).count
project.project_score.update_attribute(:board_message_num, messages_count)
end
# update issues
unless project.issues.nil?
issues_count = project.issues.count
project.project_score.update_attribute(:issue_num, issues_count)
end
# update issue's journal
# if !project.project_score.nil? && !project.project_score.issue_journal_num.nil?
# project.project_score.update_attribute(:issue_journal_num, project.project_score.issue_journal_num)
# end
# update news
unless project.news.nil?
news_count = project.news.count
project.project_score.update_attribute(:news_num, news_count)
end
# update acts
acts = ForgeActivity.where("project_id = ?", project.id)
unless acts.blank?
project.project_score.update_attribute(:act_num, acts.count)
end
# update attach
unless project.attachments.nil?
attachments_count = project.attachments.count
project.project_score.update_attribute(:attach_num, attachments_count)
end
end
end
end
end
end
def down
end
end

File diff suppressed because it is too large Load Diff