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

20170508190732_add_foreign_key_to_ci_variables.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 20ecaa2c36c2a02ef4241314574e7c987d1e8f5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class AddForeignKeyToCiVariables < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  def up
    execute <<~SQL
      DELETE FROM ci_variables
      WHERE NOT EXISTS (
        SELECT true
        FROM projects
        WHERE projects.id = ci_variables.project_id
      )
    SQL

    add_concurrent_foreign_key(:ci_variables, :projects, column: :project_id)
  end

  def down
    remove_foreign_key(:ci_variables, column: :project_id)
  end
end