Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab
Commits
0e186a05
Commit
0e186a05
authored
6 years ago
by
Mark Chao
Browse files
Options
Downloads
Patches
Plain Diff
Avoid query and model initialization
Finding id is enough for update
parent
fb7c62b8
No related branches found
No related tags found
1 merge request
!8669
[Data migration] Sync Approver/ApproverGroup with ApprovalRule/ApprovalRuleMember
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ee/lib/gitlab/background_migration/migrate_approver_to_approval_rules.rb
+13
-13
13 additions, 13 deletions
...ackground_migration/migrate_approver_to_approval_rules.rb
with
13 additions
and
13 deletions
ee/lib/gitlab/background_migration/migrate_approver_to_approval_rules.rb
+
13
−
13
View file @
0e186a05
...
...
@@ -19,8 +19,6 @@ class ApproverGroup < ActiveRecord::Base
class
ApprovalMergeRequestRule
<
ActiveRecord
::
Base
self
.
table_name
=
'approval_merge_request_rules'
include
Gitlab
::
Utils
::
StrongMemoize
belongs_to
:merge_request
scope
:code_owner
,
->
{
where
(
code_owner:
true
)
}
scope
:regular
,
->
{
where
(
code_owner:
false
)
}
# Non code owner rule
...
...
@@ -57,15 +55,17 @@ class MergeRequest < ActiveRecord::Base
belongs_to
:target_project
,
class_name:
"Project"
has_many
:approval_rules
,
class_name:
'ApprovalMergeRequestRule'
def
approvers
Approver
.
where
(
target_type:
'MergeRequest'
,
target_id:
id
)
def
approver
_id
s
@approver_ids
||=
Approver
.
where
(
target_type:
'MergeRequest'
,
target_id:
id
)
.
pluck
(
:user_id
)
end
def
approver_groups
ApproverGroup
.
where
(
target_type:
'MergeRequest'
,
target_id:
id
)
def
approver_group
_id
s
@approver_group_ids
||=
ApproverGroup
.
where
(
target_type:
'MergeRequest'
,
target_id:
id
)
.
pluck
(
:group_id
)
end
def
sync_code_owners_with_approvers
return
if
state
==
'merged'
||
state
==
'closed'
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
do
::
MergeRequest
.
find
(
id
).
sync_code_owners_with_approvers
end
...
...
@@ -77,12 +77,12 @@ class Project < ActiveRecord::Base
has_many
:approval_rules
,
class_name:
'ApprovalProjectRule'
def
approvers
Approver
.
where
(
target_type:
'Project'
,
target_id:
id
)
def
approver
_id
s
@approver_ids
||=
Approver
.
where
(
target_type:
'Project'
,
target_id:
id
)
.
pluck
(
:user_id
)
end
def
approver_groups
ApproverGroup
.
where
(
target_type:
'Project'
,
target_id:
id
)
def
approver_group
_id
s
@approver_group_ids
||=
ApproverGroup
.
where
(
target_type:
'Project'
,
target_id:
id
)
.
pluck
(
:group_id
)
end
end
...
...
@@ -131,8 +131,8 @@ def sync_rule
end
rule
=
find_or_create_rule
rule
.
user_ids
=
target
.
approver
s
.
pluck
(
:user
_id
)
rule
.
group_ids
=
target
.
approver_
groups
.
pluck
(
:
group_id
)
rule
.
user_ids
=
target
.
approver_id
s
rule
.
group_ids
=
target
.
approver_group_id
s
rule
end
...
...
@@ -159,7 +159,7 @@ def find_or_create_rule
end
def
approvers_exists?
target
.
approver
s
.
to_a
.
any?
||
target
.
approver_group
s
.
to_a
.
any?
target
.
approver
_ids
.
any?
||
target
.
approver_group
_ids
.
any?
end
end
end
...
...
This diff is collapsed.
Click to expand it.
Douwe Maan
@DouweM
mentioned in commit
e002aea0
·
6 years ago
mentioned in commit
e002aea0
mentioned in commit e002aea04f5d54f2debc9b0aa3bb6580fa2a7142
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment