diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-09-21 10:07:53 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-09-21 10:07:53 +0200 |
commit | a37e591e7414f51ca9076e966c724030225528db (patch) | |
tree | b50cc3cf9c52840d3058b9b103535fd91f1a076a /lib | |
parent | b2a90216858160840fdfbe7a221c317a6c073f22 (diff) | |
download | gitlab-ce-a37e591e7414f51ca9076e966c724030225528db.tar.gz |
Use INSERT INTO to insert tags
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ci/migrate/tags.rb | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/ci/migrate/tags.rb b/lib/ci/migrate/tags.rb index 2e4872f0716..97e043ece27 100644 --- a/lib/ci/migrate/tags.rb +++ b/lib/ci/migrate/tags.rb @@ -4,14 +4,15 @@ module Ci module Migrate class Tags def restore - ActiveRecord::Base.transaction do - puts 'Inserting tags...' - connection.execute( - 'INSERT INTO tags (name) ' + - 'SELECT ci_tags.name FROM ci_tags ' + - 'WHERE (SELECT COUNT(*) FROM tags WHERE tags.name = ci_tags.name)=0' - ) + puts 'Inserting tags...' + connection.select_all('SELECT ci_tags.name FROM ci_tags').each do |tag| + begin + connection.execute("INSERT INTO tags (name) VALUES(#{ActiveRecord::Base::sanitize(tag['name'])})") + rescue ActiveRecord::RecordNotUnique + end + end + ActiveRecord::Base.transaction do puts 'Deleting old taggings...' connection.execute "DELETE FROM taggings WHERE context = 'tags' AND taggable_type LIKE 'Ci::%'" |