Created
June 18, 2012 09:43
-
-
Save jhjguxin/2947663 to your computer and use it in GitHub Desktop.
tag迁移 -- Andersen_Fan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in db | |
update knowledges set auto_tags = tags; | |
update questions set auto_tags = tags; | |
alter table tags rename to tags_bak; | |
rake db:migrate | |
#TODO? for identity/timeline/category tags? | |
# in rails console | |
class TagBak < ActiveRecord::Base | |
set_table_name "tags_bak" | |
end | |
class CategoryBase < ActiveRecord::Base | |
set_table_name "category_bases" | |
end | |
class Identity < CategoryBase | |
end | |
class TimeLine < CategoryBase | |
end | |
class Category < CategoryBase | |
end | |
# for knowledges | |
# delete the tags column of table knowledges | |
Knowledge.all.each do |m| m.tag_list=m.auto_tags.split(",").collect{|t| begin;TagBak.find(t).name if t and !t.empty?;end}.join(",");m.save; end;puts | |
# for questions | |
# delete the tags column of table questions | |
Question.all.each do |m| m.tag_list=m.auto_tags.split(",").collect{|t| begin;TagBak.find(t).name if t and !t.empty?;end}.join(",");m.save; end;puts | |
#更新所有timeline: | |
TimeLine.all.each do |m| | |
Tag.find_by_name(m.name).taggings.each do |tgg| | |
tgg.context="timelines"; | |
tgg.save; | |
end; | |
end | |
#更新所有category: | |
Category.all.each do |m| | |
Tag.find_by_name(m.name).taggings.each do |tgg| | |
tgg.context="categories"; | |
tgg.save; | |
end; | |
end | |
#更新所有identity: | |
Identity.all.each do |m| | |
Tag.find_by_name(m.name).taggings.each do |tgg| | |
tgg.context="identities"; | |
tgg.save; | |
end; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment