BigW Consortium Gitlab

20130506095501_remove_project_id_from_key.rb 489 Bytes
Newer Older
1
# rubocop:disable all
2 3
class RemoveProjectIdFromKey < ActiveRecord::Migration
  def up
4 5 6 7
    puts 'Migrate deploy keys: '
    Key.where('project_id IS NOT NULL').update_all(type: 'DeployKey')

    DeployKey.all.each do |key|
skv committed
8
      project = Project.find_by(id: key.project_id)
9 10 11 12 13 14 15 16
      if project
        project.deploy_keys << key
        print '.'
      end
    end

    puts 'Done'

17 18 19 20 21 22 23
    remove_column :keys, :project_id
  end

  def down
    add_column :keys, :project_id, :integer
  end
end