-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate.txt
56 lines (48 loc) · 1.71 KB
/
migrate.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'open-uri'
# desc "Migrates article images"
# task :mai => :environment do
# Rails.logger = Logger.new(STDOUT)
# # Articles
# Article.find_each do |article|
# begin
# filename = File.basename(URI.parse(article.image.url).to_s)
# puts filename, article.image.url
# file = URI.open(article.image.url)
# article.image_new.attach(io: file, filename: filename )
# rescue => e
# puts e
# ## log/handle your errors in order to retry later
# end
# end
# # Projects
# Project.find_each do |project|
# begin
# urls = project.project_images.map(&:images).map(&:url)
# urls.each do |url|
# filename = File.basename(URI.parse(url).to_s)
# puts filename, url
# file = URI.open(url)
# project.project_images_new.attach(io: file, filename: filename)
# end
# rescue => e
# puts e
# ## log/handle your errors in order to retry later
# end
# end
# # a.project_images.map {|i| ActiveStorage::Blob.service.url(i.key, disposition: 'inline', content_type: i.content_type, filename: i.filename, expires_in: 200_000)}
# end
uniques = Project.all.map(&:features).map{|feature| feature.gsub(/[{}]/,'').split(',').map{|h| h1,h2 = h.split('=>'); {h1 => h2}}}.flatten.uniq { |p| p.keys }
uniques.each do |hash|
key = hash.keys[0]
value = hash.values[0]
Tag.create(name: key, icon: value)
end
tag_map.each_with_index do |arr, index|
arr.each do |tag|
project_id = project_ids[index]
match = Tag.find_by(name: tag)
puts project_id
puts match
ProjectTag.create(project_id: project_id, tag_id: match.id)
end
end