migrate script
This commit is contained in:
parent
d0c1d488fc
commit
311f8acbe9
|
@ -174,4 +174,31 @@ namespace :universal_table_tasks do
|
|||
File.delete(file_path) if File.exist?(file_path)
|
||||
puts "Import finished. Total entries in table: #{table.table_entries.count}"
|
||||
end
|
||||
|
||||
desc "Migrate old tags to new tags"
|
||||
task :migrate_tags => :environment do
|
||||
module_app = ModuleApp.find_by_key("universal_table")
|
||||
dataset = {}
|
||||
TableTag.all.each do |tt|
|
||||
next if tt.title.blank? # Skip if tag name is blank
|
||||
puts "Processing tag: #{tt.title}"
|
||||
module_app.reload
|
||||
hashtag = module_app.hashtags.where(name: tt.title).first_or_initialize
|
||||
hashtag.module_app_ids << module_app.id.to_s unless hashtag.module_app_ids.include?(module_app.id.to_s)
|
||||
puts "New record #{hashtag.new_record?}"
|
||||
hashtag.save if hashtag.new_record?
|
||||
puts "Hashtag ID: #{hashtag.id} - #{hashtag.name}"
|
||||
tt.table_entries.each do |te|
|
||||
unless te.hashtags.include?(hashtag)
|
||||
dataset[te] ||= []
|
||||
dataset[te] << hashtag.id
|
||||
end
|
||||
end
|
||||
end
|
||||
dataset.each do |te, tag_ids|
|
||||
puts "Updating TableEntry #{te.id} with tags: #{tag_ids.join(', ')}"
|
||||
te.hashtags= tag_ids
|
||||
te.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue