Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-07-29 20:19:26 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-07-29 20:19:26 +0400
commitd45a6b2941f30d71f828e0fc8adaeab19f87b1a0 (patch)
treed774fc68fdafdce0936924418be2e10743f2af74 /db/migrate
parent6fb9badcaef5152c60bf4091899a84b34f5cc1b8 (diff)
Migrate issue/mr labels from act_as_taggable to own labels
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20140729152420_migrate_taggable_labels.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/db/migrate/20140729152420_migrate_taggable_labels.rb b/db/migrate/20140729152420_migrate_taggable_labels.rb
new file mode 100644
index 00000000000..0b844720ba1
--- /dev/null
+++ b/db/migrate/20140729152420_migrate_taggable_labels.rb
@@ -0,0 +1,27 @@
+class MigrateTaggableLabels < ActiveRecord::Migration
+ def up
+ taggings = ActsAsTaggableOn::Tagging.where(taggable_type: ['Issue', 'MergeRequest'], context: 'labels')
+ taggings.find_each(batch_size: 500) do |tagging|
+ create_label_from_tagging(tagging)
+ end
+ end
+
+ def down
+ Label.destroy_all
+ LabelLink.destroy_all
+ end
+
+ private
+
+ def create_label_from_tagging(tagging)
+ target = tagging.taggable
+ label_name = tagging.tag.name
+ label = target.project.labels.find_or_create_by(title: label_name)
+
+ if LabelLink.create(label: label, target: target)
+ print '.'
+ else
+ print 'F'
+ end
+ end
+end