diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-09-15 00:28:11 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-09-15 00:29:20 +0200 |
commit | 9a3d0f1d92ee99792b40c401f83121adb8fd3387 (patch) | |
tree | 1c9a8ffd9941c4467e0b0ed63bac95d2c5cd86af | |
parent | ebd06d7e7da9f4df846f1af2ca49c6c64f1f90b0 (diff) | |
download | gitlab-ce-9a3d0f1d92ee99792b40c401f83121adb8fd3387.tar.gz |
Add rake task to migrate CI tags
-rw-r--r-- | db/migrate/20150914215247_add_ci_tags.rb | 23 | ||||
-rw-r--r-- | db/schema.rb | 22 | ||||
-rw-r--r-- | lib/tasks/ci/migrate.rake | 40 |
3 files changed, 84 insertions, 1 deletions
diff --git a/db/migrate/20150914215247_add_ci_tags.rb b/db/migrate/20150914215247_add_ci_tags.rb new file mode 100644 index 00000000000..df3390e8a82 --- /dev/null +++ b/db/migrate/20150914215247_add_ci_tags.rb @@ -0,0 +1,23 @@ +class AddCiTags < ActiveRecord::Migration + def change + create_table "ci_taggings", force: true do |t| + t.integer "tag_id" + t.integer "taggable_id" + t.string "taggable_type" + t.integer "tagger_id" + t.string "tagger_type" + t.string "context", limit: 128 + t.datetime "created_at" + end + + add_index "ci_taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "ci_taggings_idx", unique: true, using: :btree + add_index "ci_taggings", ["taggable_id", "taggable_type", "context"], name: "index_ci_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree + + create_table "ci_tags", force: true do |t| + t.string "name" + t.integer "taggings_count", default: 0 + end + + add_index "ci_tags", ["name"], name: "index_ci_tags_on_name", unique: true, using: :btree + end +end diff --git a/db/schema.rb b/db/schema.rb index 30b4832c1f3..5fd764bf698 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: 20150902001023) do +ActiveRecord::Schema.define(version: 20150914215247) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -223,6 +223,26 @@ ActiveRecord::Schema.define(version: 20150902001023) do add_index "ci_sessions", ["session_id"], name: "index_ci_sessions_on_session_id", using: :btree add_index "ci_sessions", ["updated_at"], name: "index_ci_sessions_on_updated_at", using: :btree + create_table "ci_taggings", force: true do |t| + t.integer "tag_id" + t.integer "taggable_id" + t.string "taggable_type" + t.integer "tagger_id" + t.string "tagger_type" + t.string "context", limit: 128 + t.datetime "created_at" + end + + add_index "ci_taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "ci_taggings_idx", unique: true, using: :btree + add_index "ci_taggings", ["taggable_id", "taggable_type", "context"], name: "index_ci_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree + + create_table "ci_tags", force: true do |t| + t.string "name" + t.integer "taggings_count", default: 0 + end + + add_index "ci_tags", ["name"], name: "index_ci_tags_on_name", unique: true, using: :btree + create_table "ci_trigger_requests", force: true do |t| t.integer "trigger_id", null: false t.text "variables" 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 |