Commit 749d3383cc390ef156d0c37a1b5f9c21062e7f9c
1 parent
4528fa98
Exists in
master
and in
4 other branches
Add migration code for existing deploy keys
Showing
1 changed file
with
13 additions
and
0 deletions
Show diff stats
db/migrate/20130506095501_remove_project_id_from_key.rb
| 1 | class RemoveProjectIdFromKey < ActiveRecord::Migration | 1 | class RemoveProjectIdFromKey < ActiveRecord::Migration |
| 2 | def up | 2 | def up |
| 3 | + puts 'Migrate deploy keys: ' | ||
| 4 | + Key.where('project_id IS NOT NULL').update_all(type: 'DeployKey') | ||
| 5 | + | ||
| 6 | + DeployKey.all.each do |key| | ||
| 7 | + project = Project.find_by_id(key.project_id) | ||
| 8 | + if project | ||
| 9 | + project.deploy_keys << key | ||
| 10 | + print '.' | ||
| 11 | + end | ||
| 12 | + end | ||
| 13 | + | ||
| 14 | + puts 'Done' | ||
| 15 | + | ||
| 3 | remove_column :keys, :project_id | 16 | remove_column :keys, :project_id |
| 4 | end | 17 | end |
| 5 | 18 |