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
12d0a64d
Commit
12d0a64d
authored
Jun 28, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract work into background migration
parent
4b3d8f38
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
101 additions
and
87 deletions
+101
-87
db/migrate/20170626202753_update_authorized_keys_file.rb
db/migrate/20170626202753_update_authorized_keys_file.rb
+2
-17
lib/gitlab/background_migration/update_authorized_keys_file_since.rb
...background_migration/update_authorized_keys_file_since.rb
+26
-0
spec/lib/gitlab/background_migration/update_authorized_keys_file_since_spec.rb
...round_migration/update_authorized_keys_file_since_spec.rb
+73
-0
spec/migrations/update_authorized_keys_file_spec.rb
spec/migrations/update_authorized_keys_file_spec.rb
+0
-70
No files found.
db/migrate/20170626202753_update_authorized_keys_file.rb
View file @
12d0a64d
...
...
@@ -7,9 +7,6 @@ class UpdateAuthorizedKeysFile < ActiveRecord::Migration
class
ApplicationSetting
<
ActiveRecord
::
Base
self
.
table_name
=
'application_settings'
end
class
Key
<
ActiveRecord
::
Base
self
.
table_name
=
'keys'
end
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
...
...
@@ -97,19 +94,7 @@ class UpdateAuthorizedKeysFile < ActiveRecord::Migration
end
def
update_authorized_keys_file_since
(
cutoff_datetime
)
add_keys_since
(
cutoff_datetime
)
remove_keys_not_found_in_db
end
def
add_keys_since
(
cutoff_datetime
)
start_key
=
Key
.
select
(
:id
).
where
(
"created_at >= ?"
,
cutoff_datetime
).
take
if
start_key
GitlabShellWorker
.
perform_async
(
:batch_add_keys_in_db_starting_from
,
start_key
.
id
)
end
end
def
remove_keys_not_found_in_db
GitlabShellWorker
.
perform_async
(
:remove_keys_not_found_in_db
)
job
=
[
'UpdateAuthorizedKeysFileSince'
,
[
cutoff_datetime
]]
BackgroundMigrationWorker
.
perform_bulk
(
job
)
end
end
lib/gitlab/background_migration/update_authorized_keys_file_since.rb
0 → 100644
View file @
12d0a64d
module
Gitlab
module
BackgroundMigration
class
UpdateAuthorizedKeysFileSince
class
Key
<
ActiveRecord
::
Base
self
.
table_name
=
'keys'
end
def
perform
(
cutoff_datetime
)
add_keys_since
(
cutoff_datetime
)
remove_keys_not_found_in_db
end
def
add_keys_since
(
cutoff_datetime
)
start_key
=
Key
.
select
(
:id
).
where
(
"created_at >= ?"
,
cutoff_datetime
).
take
if
start_key
GitlabShellWorker
.
perform_async
(
:batch_add_keys_in_db_starting_from
,
start_key
.
id
)
end
end
def
remove_keys_not_found_in_db
GitlabShellWorker
.
perform_async
(
:remove_keys_not_found_in_db
)
end
end
end
end
spec/lib/gitlab/background_migration/update_authorized_keys_file_since_spec.rb
0 → 100644
View file @
12d0a64d
require
'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
UpdateAuthorizedKeysFileSince
do
describe
'#perform'
do
let!
(
:cutoff_datetime
)
{
DateTime
.
now
}
subject
{
described_class
.
new
.
perform
(
cutoff_datetime
)
}
context
'when an SSH key was created after the cutoff datetime'
do
before
do
Timecop
.
freeze
end
after
do
Timecop
.
return
end
before
do
Timecop
.
travel
1
.
day
.
from_now
@key
=
create
(
:key
)
end
it
'queues a batch_add_keys_from call to GitlabShellWorker, including the start key ID'
do
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
).
with
(
:batch_add_keys_in_db_starting_from
,
@key
.
id
)
allow
(
GitlabShellWorker
).
to
receive
(
:perform_async
).
with
(
:remove_keys_not_found_in_db
)
subject
end
end
it
'queues a remove_keys_not_found_in_db call to GitlabShellWorker'
do
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
).
with
(
:remove_keys_not_found_in_db
)
subject
end
end
describe
'#add_keys_since'
do
let!
(
:cutoff_datetime
)
{
DateTime
.
now
}
subject
{
described_class
.
new
.
add_keys_since
(
cutoff_datetime
)
}
before
do
Timecop
.
freeze
end
after
do
Timecop
.
return
end
context
'when an SSH key was created after the cutoff datetime'
do
before
do
Timecop
.
travel
1
.
day
.
from_now
@key
=
create
(
:key
)
end
it
'queues a batch_add_keys_from call to GitlabShellWorker, including the start key ID'
do
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
).
with
(
:batch_add_keys_in_db_starting_from
,
@key
.
id
)
subject
end
end
context
'when an SSH key was not created after the cutoff datetime'
do
it
'does not use GitlabShellWorker'
do
expect
(
GitlabShellWorker
).
not_to
receive
(
:perform_async
)
subject
end
end
end
describe
'#remove_keys_not_found_in_db'
do
it
'queues a rm_keys_not_in_db call to GitlabShellWorker'
do
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
).
with
(
:remove_keys_not_found_in_db
)
described_class
.
new
.
remove_keys_not_found_in_db
end
end
end
spec/migrations/update_authorized_keys_file_spec.rb
View file @
12d0a64d
...
...
@@ -159,74 +159,4 @@ describe UpdateAuthorizedKeysFile do
end
end
end
describe
'#update_authorized_keys_file_since'
do
let!
(
:cutoff_datetime
)
{
DateTime
.
now
}
subject
{
migration
.
update_authorized_keys_file_since
(
cutoff_datetime
)
}
context
'when an SSH key was created after the cutoff datetime'
do
before
do
Timecop
.
freeze
end
after
do
Timecop
.
return
end
before
do
Timecop
.
travel
1
.
day
.
from_now
@key
=
create
(
:key
)
end
it
'queues a batch_add_keys_from call to GitlabShellWorker, including the start key ID'
do
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
).
with
(
:batch_add_keys_in_db_starting_from
,
@key
.
id
)
allow
(
GitlabShellWorker
).
to
receive
(
:perform_async
).
with
(
:remove_keys_not_found_in_db
)
subject
end
end
it
'queues a remove_keys_not_found_in_db call to GitlabShellWorker'
do
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
).
with
(
:remove_keys_not_found_in_db
)
subject
end
end
describe
'#add_keys_since'
do
let!
(
:cutoff_datetime
)
{
DateTime
.
now
}
subject
{
migration
.
add_keys_since
(
cutoff_datetime
)
}
before
do
Timecop
.
freeze
end
after
do
Timecop
.
return
end
context
'when an SSH key was created after the cutoff datetime'
do
before
do
Timecop
.
travel
1
.
day
.
from_now
@key
=
create
(
:key
)
end
it
'queues a batch_add_keys_from call to GitlabShellWorker, including the start key ID'
do
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
).
with
(
:batch_add_keys_in_db_starting_from
,
@key
.
id
)
subject
end
end
context
'when an SSH key was not created after the cutoff datetime'
do
it
'does not use GitlabShellWorker'
do
expect
(
GitlabShellWorker
).
not_to
receive
(
:perform_async
)
subject
end
end
end
describe
'#remove_keys_not_found_in_db'
do
it
'queues a rm_keys_not_in_db call to GitlabShellWorker'
do
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
).
with
(
:remove_keys_not_found_in_db
)
migration
.
remove_keys_not_found_in_db
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