summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-05-07 18:17:58 +0300
committerValery Sizov <vsv2711@gmail.com>2015-05-07 18:17:58 +0300
commitb60717604c8f7b2cb089d4fd30cc282d4f77a85f (patch)
treeb161d969dc92ddb17bd43bb57bcdcddab815bf7d
parent415648e2555e25d30f64f4c2642cf149f6965859 (diff)
downloadgitlab-ce-tag_dup.tar.gz
remove tag duplicatestag_dup
-rw-r--r--db/migrate/20150425164647_remove_duplicate_tags.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/db/migrate/20150425164647_remove_duplicate_tags.rb b/db/migrate/20150425164647_remove_duplicate_tags.rb
new file mode 100644
index 00000000000..1a9152cb965
--- /dev/null
+++ b/db/migrate/20150425164647_remove_duplicate_tags.rb
@@ -0,0 +1,16 @@
+class RemoveDuplicateTags < ActiveRecord::Migration
+ def up
+ select_all("SELECT name, COUNT(id) as cnt FROM tags GROUP BY name HAVING COUNT(id) > 1").each do |tag|
+ duplicate_ids = select_all("SELECT id FROM tags WHERE name = '#{tag["name"]}'").map{|tag| tag["id"]}
+ origin_tag_id = duplicate_ids.first
+ duplicate_ids.delete origin_tag_id
+
+ execute("UPDATE taggings SET tag_id = #{origin_tag_id} WHERE tag_id IN(#{duplicate_ids.join(",")})")
+ execute("DELETE FROM tags WHERE id IN(#{duplicate_ids.join(",")})")
+ end
+ end
+
+ def down
+
+ end
+end