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
6e0a4fc1
Commit
6e0a4fc1
authored
Oct 05, 2017
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert migrations to generate subkeys to a background migration
parent
dd139e65
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
18 deletions
+32
-18
db/post_migrate/20171005130944_schedule_create_gpg_key_subkeys_from_gpg_keys.rb
...05130944_schedule_create_gpg_key_subkeys_from_gpg_keys.rb
+25
-0
db/schema.rb
db/schema.rb
+1
-1
lib/gitlab/background_migration/create_gpg_key_subkeys_from_gpg_keys.rb
...kground_migration/create_gpg_key_subkeys_from_gpg_keys.rb
+6
-17
No files found.
db/post_migrate/20171005130944_schedule_create_gpg_key_subkeys_from_gpg_keys.rb
0 → 100644
View file @
6e0a4fc1
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
ScheduleCreateGpgKeySubkeysFromGpgKeys
<
ActiveRecord
::
Migration
disable_ddl_transaction!
DOWNTIME
=
false
class
GpgKey
<
ActiveRecord
::
Base
self
.
table_name
=
'gpg_keys'
end
def
up
GpgKey
.
select
(
:id
).
in_batches
do
|
relation
|
jobs
=
relation
.
pluck
(
:id
).
map
do
|
id
|
[
'CreateGpgKeySubkeysFromGpgKeys'
,
[
id
]]
end
BackgroundMigrationWorker
.
perform_bulk
(
jobs
)
end
end
def
down
end
end
db/schema.rb
View file @
6e0a4fc1
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2017100
41214
44
)
do
ActiveRecord
::
Schema
.
define
(
version:
2017100
51309
44
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
...
db/post_migrate/20171002161539_create_gpg_key_subkeys_for_existing
_gpg_keys.rb
→
lib/gitlab/background_migration/create_gpg_key_subkeys_from
_gpg_keys.rb
View file @
6e0a4fc1
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
class
Gitlab::BackgroundMigration::CreateGpgKeySubkeysFromGpgKeys
# for more information on how to write migrations for GitLab.
class
CreateGpgKeySubkeysForExistingGpgKeys
<
ActiveRecord
::
Migration
disable_ddl_transaction!
DOWNTIME
=
false
class
GpgKey
<
ActiveRecord
::
Base
class
GpgKey
<
ActiveRecord
::
Base
self
.
table_name
=
'gpg_keys'
self
.
table_name
=
'gpg_keys'
...
@@ -27,17 +20,13 @@ class CreateGpgKeySubkeysForExistingGpgKeys < ActiveRecord::Migration
...
@@ -27,17 +20,13 @@ class CreateGpgKeySubkeysForExistingGpgKeys < ActiveRecord::Migration
sha_attribute
:fingerprint
sha_attribute
:fingerprint
end
end
def
up
def
perform
(
gpg_key_id
)
GpgKey
.
with_subkeys
.
each_batch
do
|
batch
|
gpg_key
=
GpgKey
.
find_by
(
id:
gpg_key_id
)
batch
.
each
do
|
gpg_key
|
next
if
gpg_key
.
subkeys
.
any?
create_subkeys
(
gpg_key
)
&&
update_signatures
(
gpg_key
)
return
if
gpg_key
.
nil?
end
return
if
gpg_key
.
subkeys
.
any?
end
end
def
down
create_subkeys
(
gpg_key
)
&&
update_signatures
(
gpg_key
)
end
end
private
private
...
...
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