Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20130506095501_remove_project_id_from_key.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6b794cfb5c133e7d717824c3c592a95ca9130bed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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

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