Commit a37e591e authored by Kamil Trzcinski's avatar Kamil Trzcinski

Use INSERT INTO to insert tags

parent b2a90216
...@@ -4,14 +4,15 @@ module Ci ...@@ -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.select_all('SELECT ci_tags.name FROM ci_tags').each do |tag|
connection.execute( begin
'INSERT INTO tags (name) ' + connection.execute("INSERT INTO tags (name) VALUES(#{ActiveRecord::Base::sanitize(tag['name'])})")
'SELECT ci_tags.name FROM ci_tags ' + rescue ActiveRecord::RecordNotUnique
'WHERE (SELECT COUNT(*) FROM tags WHERE tags.name = ci_tags.name)=0' 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::%'"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment