From 8b2126d2a7132013d007a321ee6286876fe27b50 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Mon, 12 Nov 2012 20:59:46 +0600 Subject: [PATCH] [refs #90] fixed migration & task for pull path --- .../20121027084602_add_helpers_columns_to_pull_request.rb | 6 +++++- lib/tasks/fix_orphan_pulls.rake | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/db/migrate/20121027084602_add_helpers_columns_to_pull_request.rb b/db/migrate/20121027084602_add_helpers_columns_to_pull_request.rb index 13b09c0a3..2a3655b73 100644 --- a/db/migrate/20121027084602_add_helpers_columns_to_pull_request.rb +++ b/db/migrate/20121027084602_add_helpers_columns_to_pull_request.rb @@ -4,7 +4,11 @@ class AddHelpersColumnsToPullRequest < ActiveRecord::Migration add_column :pull_requests, :from_project_name, :string # includes generate error "undefined method `repo' for nil:NilClass" # update not orphan pulls. For other need execute a task project:fix_orphan_pulls - PullRequest.joins(:from_project).each {|pull| pull.from_project_name = pull.from_project.name} + PullRequest.joins(:from_project).each do |pull| + pull.from_project_name = pull.from_project.name + pull.from_project_owner_uname = pull.from_project.owner.uname + pull.save + end end def down diff --git a/lib/tasks/fix_orphan_pulls.rake b/lib/tasks/fix_orphan_pulls.rake index 21dd94ed2..54b4d41a5 100644 --- a/lib/tasks/fix_orphan_pulls.rake +++ b/lib/tasks/fix_orphan_pulls.rake @@ -5,7 +5,12 @@ namespace :project do say "Pull requests total count is #{PullRequest.count}" PullRequest.all.each_with_index do |pull, ind| say "Check pull with id:#{pull.id} (#{ind+1}/#{PullRequest.count})" - unless pull.from_project.present? + if pull.from_project.present? + print ' updating...' + pull.from_project_name = pull.from_project.name + pull.from_project_owner_uname = pull.from_project.owner.uname + say pull.save(:validate => false) ? 'success' : 'fail!' + else print ' its orphan! updating...' parent_path = File.join(APP_CONFIG['git_path'], 'pull_requests', pull.to_project.owner.uname, pull.to_project.name) Dir.chdir(parent_path) do