summaryrefslogtreecommitdiff
path: root/db/migrate
diff options
context:
space:
mode:
authorRubén Dávila <ruben@gitlab.com>2017-10-02 21:08:59 -0500
committerRubén Dávila <ruben@gitlab.com>2017-10-05 08:26:02 -0500
commit8d296b62e4534820feb94cfe0d8b5d3e34f6ee33 (patch)
tree5e304d7a0cfb4e3ff39fa1a63e039944a5926095 /db/migrate
parent8b0397041866c0e2bcbf4c462100fc681d96f893 (diff)
downloadgitlab-ce-8d296b62e4534820feb94cfe0d8b5d3e34f6ee33.tar.gz
Convert migration to a post deployment migration
This migration can take a bit of time to complete and I don't want to delay the deployment process.
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20171002161539_create_gpg_key_subkeys_for_existing_gpg_keys.rb59
1 files changed, 0 insertions, 59 deletions
diff --git a/db/migrate/20171002161539_create_gpg_key_subkeys_for_existing_gpg_keys.rb b/db/migrate/20171002161539_create_gpg_key_subkeys_for_existing_gpg_keys.rb
deleted file mode 100644
index 355fbfbbede..00000000000
--- a/db/migrate/20171002161539_create_gpg_key_subkeys_for_existing_gpg_keys.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-# See http://doc.gitlab.com/ce/development/migration_style_guide.html
-# for more information on how to write migrations for GitLab.
-
-class CreateGpgKeySubkeysForExistingGpgKeys < ActiveRecord::Migration
- disable_ddl_transaction!
-
- DOWNTIME = false
-
- class GpgKey < ActiveRecord::Base
- self.table_name = 'gpg_keys'
-
- include EachBatch
- include ShaAttribute
-
- sha_attribute :primary_keyid
- sha_attribute :fingerprint
-
- has_many :subkeys, class_name: 'GpgKeySubkey'
- end
-
- class GpgKeySubkey < ActiveRecord::Base
- self.table_name = 'gpg_key_subkeys'
-
- include ShaAttribute
-
- sha_attribute :keyid
- sha_attribute :fingerprint
- end
-
- def up
- GpgKey.each_batch do |batch|
- batch.each do |gpg_key|
- create_subkeys(gpg_key) && update_signatures(gpg_key)
- end
- end
- end
-
- def down
- end
-
- private
-
- def create_subkeys(gpg_key)
- gpg_subkeys = Gitlab::Gpg.subkeys_from_key(gpg_key.key)
-
- gpg_subkeys[gpg_key.primary_keyid.upcase]&.each do |subkey_data|
- gpg_key.subkeys.build(keyid: subkey_data[:keyid], fingerprint: subkey_data[:fingerprint])
- end
-
- # Improve latency by doing all INSERTs in a single call
- GpgKey.transaction do
- gpg_key.save!
- end
- end
-
- def update_signatures(gpg_key)
- InvalidGpgSignatureUpdateWorker.perform_async(gpg_key.id)
- end
-end