Add migration code for existing deploy keys

This commit is contained in:
Dmitriy Zaporozhets 2013-05-06 17:42:13 +03:00
parent 4528fa9817
commit 749d3383cc
1 changed files with 13 additions and 0 deletions

View File

@ -1,5 +1,18 @@
class RemoveProjectIdFromKey < ActiveRecord::Migration
def up
puts 'Migrate deploy keys: '
Key.where('project_id IS NOT NULL').update_all(type: 'DeployKey')
DeployKey.all.each do |key|
project = Project.find_by_id(key.project_id)
if project
project.deploy_keys << key
print '.'
end
end
puts 'Done'
remove_column :keys, :project_id
end