diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-07-29 19:19:26 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-07-29 19:19:26 +0300 |
commit | d45a6b2941f30d71f828e0fc8adaeab19f87b1a0 (patch) | |
tree | d774fc68fdafdce0936924418be2e10743f2af74 /db | |
parent | 6fb9badcaef5152c60bf4091899a84b34f5cc1b8 (diff) | |
download | gitlab-ce-d45a6b2941f30d71f828e0fc8adaeab19f87b1a0.tar.gz |
Migrate issue/mr labels from act_as_taggable to own labels
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20140729152420_migrate_taggable_labels.rb | 27 | ||||
-rw-r--r-- | db/schema.rb | 2 |
2 files changed, 28 insertions, 1 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 diff --git a/db/schema.rb b/db/schema.rb index 77dac2954d4..9d8775c0193 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140729145339) do +ActiveRecord::Schema.define(version: 20140729152420) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |