Commit 8e13162a authored by Timothy Andrew's avatar Timothy Andrew

Migrate protected branch access levels to match constants in `Gitlab::Access`

- In the final round of review (!5081), we moved the protected branch
  access levels from Rails enums to constants from Gitlab::Access.

- The migrations that moved us from the old data model (a single
  protected_branches table with developers_can_push and
  developers_can_merge flags) to the new one (separate tables for
  push_access_levels and merge_access_levels) was not updated.

- These migrations still used 0 to mean "Masters" and 1 to mean
  "Developers" (matching the previous Rails enum), while Gitlab::Access
  uses 40 and 30 for these, respectively.

- Once the migrations run, our data gets into a broken state.

- We fix this by migrating all `0`s to `40` and all `1`s to `30`.

- https://gitlab.com/gitlab-org/gitlab-ce/issues/20606#note_13561628

= Caveats =

- In Gitlab::Access, 0 represents NO_ACCESS. When we run this migration,
  all protected branches with "No one" as an access level will be
  changed to "Masters"
parent 532202a5
...@@ -14,7 +14,7 @@ class MoveFromDevelopersCanMergeToProtectedBranchesMergeAccess < ActiveRecord::M ...@@ -14,7 +14,7 @@ class MoveFromDevelopersCanMergeToProtectedBranchesMergeAccess < ActiveRecord::M
def up def up
execute <<-HEREDOC execute <<-HEREDOC
INSERT into protected_branch_merge_access_levels (protected_branch_id, access_level, created_at, updated_at) INSERT into protected_branch_merge_access_levels (protected_branch_id, access_level, created_at, updated_at)
SELECT id, (CASE WHEN developers_can_merge THEN 1 ELSE 0 END), now(), now() SELECT id, (CASE WHEN developers_can_merge THEN 30 ELSE 40 END), now(), now()
FROM protected_branches FROM protected_branches
HEREDOC HEREDOC
end end
...@@ -23,7 +23,7 @@ class MoveFromDevelopersCanMergeToProtectedBranchesMergeAccess < ActiveRecord::M ...@@ -23,7 +23,7 @@ class MoveFromDevelopersCanMergeToProtectedBranchesMergeAccess < ActiveRecord::M
execute <<-HEREDOC execute <<-HEREDOC
UPDATE protected_branches SET developers_can_merge = TRUE UPDATE protected_branches SET developers_can_merge = TRUE
WHERE id IN (SELECT protected_branch_id FROM protected_branch_merge_access_levels WHERE id IN (SELECT protected_branch_id FROM protected_branch_merge_access_levels
WHERE access_level = 1); WHERE access_level = 30);
HEREDOC HEREDOC
end end
end end
...@@ -14,7 +14,7 @@ class MoveFromDevelopersCanPushToProtectedBranchesPushAccess < ActiveRecord::Mig ...@@ -14,7 +14,7 @@ class MoveFromDevelopersCanPushToProtectedBranchesPushAccess < ActiveRecord::Mig
def up def up
execute <<-HEREDOC execute <<-HEREDOC
INSERT into protected_branch_push_access_levels (protected_branch_id, access_level, created_at, updated_at) 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() SELECT id, (CASE WHEN developers_can_push THEN 30 ELSE 40 END), now(), now()
FROM protected_branches FROM protected_branches
HEREDOC HEREDOC
end end
...@@ -23,7 +23,7 @@ class MoveFromDevelopersCanPushToProtectedBranchesPushAccess < ActiveRecord::Mig ...@@ -23,7 +23,7 @@ class MoveFromDevelopersCanPushToProtectedBranchesPushAccess < ActiveRecord::Mig
execute <<-HEREDOC execute <<-HEREDOC
UPDATE protected_branches SET developers_can_push = TRUE UPDATE protected_branches SET developers_can_push = TRUE
WHERE id IN (SELECT protected_branch_id FROM protected_branch_push_access_levels WHERE id IN (SELECT protected_branch_id FROM protected_branch_push_access_levels
WHERE access_level = 1); WHERE access_level = 30);
HEREDOC HEREDOC
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment