Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8cc62f6c
Commit
8cc62f6c
authored
Jan 31, 2019
by
Mark Chao
Committed by
Bob Van Landuyt
Feb 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Loop through project rules directly
Cut intermediate step
parent
6315d2fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
7 deletions
+6
-7
ee/db/migrate/20190114040404_correct_approvals_required.rb
ee/db/migrate/20190114040404_correct_approvals_required.rb
+6
-7
No files found.
ee/db/migrate/20190114040404_correct_approvals_required.rb
View file @
8cc62f6c
...
...
@@ -15,22 +15,21 @@ class CorrectApprovalsRequired < ActiveRecord::Migration[5.0]
class
ApprovalProjectRule
<
ActiveRecord
::
Base
self
.
table_name
=
'approval_project_rules'
has_many
:approval_merge_request_rule_source
has_many
:approval_merge_request_rules
,
through: :approval_merge_request_rule_source
end
def
up
project_rule_ids
=
ApprovalMergeReques
tRule
.
joins
(
:approval_
project_rule
)
ApprovalProjec
tRule
.
joins
(
:approval_
merge_request_rules
)
.
where
(
'approval_merge_request_rules.approvals_required = 0 AND approval_project_rules.approvals_required > 0'
)
.
pluck
(
'approval_project_rules.id'
)
ApprovalProjectRule
.
where
(
id:
project_rule_ids
).
find_each
do
|
project_rule
|
# rubocop:disable GitlabSecurity/SqlInjection
.
find_each
do
|
project_rule
|
# Pluck as MySQL prohibits subquery that references the table being updated
mr_rule_ids
=
ApprovalMergeRequestRule
.
joins
(
:approval_merge_request_rule_source
)
.
where
(
"approval_merge_request_rules.approvals_required = 0 AND approval_merge_request_rule_sources.approval_project_rule_id =
#{
project_rule
.
id
}
"
)
.
pluck
(
'approval_merge_request_rules.id'
)
# rubocop:enable GitlabSecurity/SqlInjection
ApprovalMergeRequestRule
.
where
(
id:
mr_rule_ids
).
update_all
(
approvals_required:
project_rule
.
approvals_required
)
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment