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
840cb644
Commit
840cb644
authored
Dec 14, 2018
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add migration progress checker
parent
2714d05a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
1 deletion
+47
-1
ee/db/post_migrate/20181204040404_migrate_project_approvers.rb
.../post_migrate/20181204040404_migrate_project_approvers.rb
+4
-1
ee/lib/gitlab/background_migration/migrate_approver_to_approval_rules_check_progress.rb
...tion/migrate_approver_to_approval_rules_check_progress.rb
+41
-0
ee/spec/migrations/migrate_project_approvers_spec.rb
ee/spec/migrations/migrate_project_approvers_spec.rb
+2
-0
No files found.
ee/db/post_migrate/20181204040404_migrate_project_approvers.rb
View file @
840cb644
...
...
@@ -16,7 +16,10 @@ class MigrateProjectApprovers < ActiveRecord::Migration[5.0]
Project
.
each_batch
(
of:
BATCH_SIZE
)
do
|
scope
,
_
|
jobs
<<
[
'MigrateApproverToApprovalRulesInBatch'
,
[
'Project'
,
scope
.
pluck
(
:id
)]]
end
BackgroundMigration
.
bulk_perform_async
(
jobs
)
BackgroundMigrationWorker
.
bulk_perform_async
(
jobs
)
check_time
=
Gitlab
::
BackgroundMigration
::
MigrateApproverToApprovalRulesCheckProgress
::
RESCHEDULE_DELAY
BackgroundMigrationWorker
.
bulk_perform_in
(
check_time
,
[[
'MigrateApproverToApprovalRulesCheckProgress'
]])
end
def
down
...
...
ee/lib/gitlab/background_migration/migrate_approver_to_approval_rules_check_progress.rb
0 → 100644
View file @
840cb644
# frozen_string_literal: true
module
Gitlab
module
BackgroundMigration
class
MigrateApproverToApprovalRulesCheckProgress
RESCHEDULE_DELAY
=
1
.
day
def
perform
if
remaining
(
'MergeRequest'
)
==
0
&&
remaining
(
'Project'
)
==
0
Feature
.
enable
(
:approval_rule
)
else
BackgroundMigrationWorker
.
perform_in
(
RESCHEDULE_DELAY
,
self
.
class
.
name
)
end
end
private
def
remaining
(
class_name
)
target_type
=
ActiveRecord
::
Base
.
connection
.
quote
(
class_name
)
sql_old_schema
=
<<-
SQL
.
strip_heredoc
SELECT count(*) FROM (
SELECT target_id FROM "approvers" WHERE "approvers"."target_type" =
#{
target_type
}
UNION
SELECT target_id FROM "approver_groups" WHERE "approver_groups"."target_type" =
#{
target_type
}
) AS target_count
SQL
sql_new_schema
=
<<-
SQL
.
strip_heredoc
SELECT count(distinct
#{
class_name
.
foreign_key
}
) from approval_
#{
class_name
.
underscore
}
_rules
SQL
count
(
sql_old_schema
)
-
count
(
sql_new_schema
)
end
def
count
(
sql
)
ActiveRecord
::
Base
.
connection
.
exec_query
(
sql
).
first
[
'count'
]
end
end
end
end
ee/spec/migrations/migrate_project_approvers_spec.rb
View file @
840cb644
...
...
@@ -13,6 +13,7 @@ describe MigrateProjectApprovers, :migration do
let
(
:approval_project_rules
)
{
table
(
:approval_project_rules
)
}
let
(
:approval_project_rules_users
)
{
table
(
:approval_project_rules_users
)
}
let
(
:users
)
{
table
(
:users
)
}
let
(
:features
)
{
table
(
:features
)
}
before
do
namespaces
.
create
(
id:
1
,
name:
'gitlab-org'
,
path:
'gitlab-org'
)
...
...
@@ -35,6 +36,7 @@ describe MigrateProjectApprovers, :migration do
expect
(
approval_project_rules_users
.
where
(
approval_project_rule_id:
rule_ids
.
first
).
pluck
(
:user_id
)).
to
contain_exactly
(
1
)
expect
(
approval_project_rules_users
.
where
(
approval_project_rule_id:
rule_ids
.
last
).
pluck
(
:user_id
)).
to
contain_exactly
(
2
)
expect
(
features
.
where
(
key:
'approval_rule'
).
exists?
).
to
eq
(
true
)
end
end
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