summaryrefslogtreecommitdiff
path: root/lib/tasks
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2015-09-15 00:28:11 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2015-09-15 00:29:20 +0200
commit9a3d0f1d92ee99792b40c401f83121adb8fd3387 (patch)
tree1c9a8ffd9941c4467e0b0ed63bac95d2c5cd86af /lib/tasks
parentebd06d7e7da9f4df846f1af2ca49c6c64f1f90b0 (diff)
downloadgitlab-ce-9a3d0f1d92ee99792b40c401f83121adb8fd3387.tar.gz
Add rake task to migrate CI tags
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/ci/migrate.rake40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/tasks/ci/migrate.rake b/lib/tasks/ci/migrate.rake
new file mode 100644
index 00000000000..c00b17f7a2d
--- /dev/null
+++ b/lib/tasks/ci/migrate.rake
@@ -0,0 +1,40 @@
+namespace :ci do
+ namespace :migrate do
+ def list_objects(type)
+ ids = ActiveRecord::Base.connection.select_all(
+ 'select distinct taggable_id from ci_taggings where taggable_type = $1',
+ nil, [[nil, type]]
+ )
+ ids.map { |id| id['taggable_id'] }
+ end
+
+ def list_tags(type, id)
+ tags = ActiveRecord::Base.connection.select_all(
+ 'select ci_tags.name from ci_tags ' +
+ 'join ci_taggings on ci_tags.id = ci_taggings.tag_id ' +
+ 'where taggable_type = $1 and taggable_id = $2 and context = $3',
+ nil, [[nil, type], [nil, id], [nil, 'tags']]
+ )
+ tags.map { |tag| tag['name'] }
+ end
+
+ desc 'GITLAB | Migrate CI tags'
+ task tags: :environment do
+ list_objects('Runner').each do |id|
+ runner = Ci::Runner.find_by_id(id)
+ if runner
+ tags = list_tags('Runner', id)
+ runner.update_attributes(tag_list: tags)
+ end
+ end
+
+ list_objects('Build').each do |id|
+ build = Ci::Build.find_by_id(id)
+ if build
+ tags = list_tags('Build', id)
+ build.update_attributes(tag_list: tags)
+ end
+ end
+ end
+ end
+end