统计数据迁移

This commit is contained in:
huang 2016-01-12 10:38:50 +08:00
parent f3b732460c
commit 1239a8b5af
7 changed files with 88 additions and 16 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,21 +1223,21 @@ 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

View File

@ -0,0 +1,19 @@
class StaticProjectBoards < ActiveRecord::Migration
def up
begin
Project.all.each do |project|
puts project.id
unless project.boards.first.nil?
boards_count = project.boards.first.topics.count
project.update_attribute(:boards_count, boards_count)
end
end
ensure
self.down
end
end
def down
Project.update_all(:boards_count => false)
end
end

View File

@ -0,0 +1,12 @@
class StaticProjectIssues < ActiveRecord::Migration
def up
Project.all.each do |project|
issues_count = project.issues.count
project.update_attribute(:issues_count, boards_count)
end
end
def down
Project.all.update_all(:issues_count => false)
end
end

View File

@ -0,0 +1,12 @@
class StaticProjectNews < ActiveRecord::Migration
def up
Project.all.each do |project|
news_count = project.news.count
project.update_attribute(:news_count, news_count)
end
end
def down
Project.all.update_all(:news_count => false)
end
end

View File

@ -0,0 +1,12 @@
class StaticProjectAttachments < ActiveRecord::Migration
def up
Project.all.each do |project|
attachments_count = project.attachments.count
project.update_attribute(:attachments_count, attachments_count)
end
end
def down
Project.all.update_all(:attachments_count => false)
end
end

View File

@ -0,0 +1,5 @@
class AddActsCountToProject < ActiveRecord::Migration
def change
add_column :projects, :acts_count, :integer, :default => false
end
end

View File

@ -0,0 +1,12 @@
class StaticProjectActs < ActiveRecord::Migration
def up
Project.all.each do |project|
acts_count = ForgeActivity.where("project_id = ?", project.id).count
project.update_attribute(:acts_count, acts_count)
end
end
def down
Project.all.update_all(:acts_count => false)
end
end