summaryrefslogtreecommitdiff
path: root/db/post_migrate/20180409170809_populate_missing_project_ci_cd_settings.rb
blob: a400a071e073dff4ba670cb82de8cdfb8a7e0c64 (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
25
26
27
28
29
30
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.

class PopulateMissingProjectCiCdSettings < ActiveRecord::Migration[4.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  def up
    # Projects created after the initial migration but before the code started
    # using ProjectCiCdSetting won't have a corresponding row in
    # project_ci_cd_settings, so let's fix that.
    execute <<~SQL
      INSERT INTO project_ci_cd_settings (project_id)
      SELECT id
      FROM projects
      WHERE NOT EXISTS (
        SELECT 1
        FROM project_ci_cd_settings
        WHERE project_ci_cd_settings.project_id = projects.id
      )
    SQL
  end

  def down
    # There's nothing to revert for this migration.
  end
end