summaryrefslogtreecommitdiff
path: root/db/migrate/20160705055308_move_from_developers_can_push_to_protected_branches_push_access.rb
blob: 56f6159d1d8e6ce1a63ae22187fa5fb83f6cf26c (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
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.

class MoveFromDevelopersCanPushToProtectedBranchesPushAccess < ActiveRecord::Migration
  DOWNTIME = true
  DOWNTIME_REASON = <<-HEREDOC
    We're creating a `push_access_level` for each `protected_branch`. If a user creates a `protected_branch` while this
    is running, we might be left with a `protected_branch` _without_ an associated `push_access_level`. The `protected_branches`
    table must not change while this is running, so downtime is required.

    https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5081#note_13247410
  HEREDOC

  def up
    execute <<-HEREDOC
      INSERT into protected_branch_push_access_levels (protected_branch_id, access_level, created_at, updated_at)
        SELECT id, (CASE WHEN developers_can_push THEN 1 ELSE 0 END), now(), now()
          FROM protected_branches
    HEREDOC
  end

  def down
    execute <<-HEREDOC
      UPDATE protected_branches SET developers_can_push = TRUE
        WHERE id IN (SELECT protected_branch_id FROM protected_branch_push_access_levels
                       WHERE access_level = 1);
    HEREDOC
  end
end