2016-07-05 06:59:15 +00:00
|
|
|
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
|
|
|
|
# for more information on how to write migrations for GitLab.
|
|
|
|
|
2018-11-13 07:27:31 +00:00
|
|
|
class MoveFromDevelopersCanPushToProtectedBranchesPushAccess < ActiveRecord::Migration[4.2]
|
2016-07-29 07:01:15 +00:00
|
|
|
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
|
|
|
|
|
2016-07-05 06:59:15 +00:00
|
|
|
def up
|
|
|
|
execute <<-HEREDOC
|
|
|
|
INSERT into protected_branch_push_access_levels (protected_branch_id, access_level, created_at, updated_at)
|
2016-08-04 04:25:02 +00:00
|
|
|
SELECT id, (CASE WHEN developers_can_push THEN 30 ELSE 40 END), now(), now()
|
2016-07-05 06:59:15 +00:00
|
|
|
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
|
2016-08-04 04:25:02 +00:00
|
|
|
WHERE access_level = 30);
|
2016-07-05 06:59:15 +00:00
|
|
|
HEREDOC
|
|
|
|
end
|
|
|
|
end
|