Use INSERT INTO to insert tags

This commit is contained in:
Kamil Trzcinski 2015-09-21 10:07:53 +02:00
parent b2a9021685
commit a37e591e74

View file

@ -4,14 +4,15 @@ module Ci
module Migrate module Migrate
class Tags class Tags
def restore def restore
ActiveRecord::Base.transaction do
puts 'Inserting tags...' puts 'Inserting tags...'
connection.execute( connection.select_all('SELECT ci_tags.name FROM ci_tags').each do |tag|
'INSERT INTO tags (name) ' + begin
'SELECT ci_tags.name FROM ci_tags ' + connection.execute("INSERT INTO tags (name) VALUES(#{ActiveRecord::Base::sanitize(tag['name'])})")
'WHERE (SELECT COUNT(*) FROM tags WHERE tags.name = ci_tags.name)=0' rescue ActiveRecord::RecordNotUnique
) end
end
ActiveRecord::Base.transaction do
puts 'Deleting old taggings...' puts 'Deleting old taggings...'
connection.execute "DELETE FROM taggings WHERE context = 'tags' AND taggable_type LIKE 'Ci::%'" connection.execute "DELETE FROM taggings WHERE context = 'tags' AND taggable_type LIKE 'Ci::%'"