summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-11-23 13:28:29 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-11-23 13:28:29 +0100
commit1143411ae848fade4050d3d8319ba5ed88a1b1da (patch)
treeb5caa33eecd10857a0c2e61b7c3225ac04b16577
parent627b4833c58b7bd9ffc852d4c76175366ab4f23b (diff)
downloadgitlab-ce-1143411ae848fade4050d3d8319ba5ed88a1b1da.tar.gz
Reduce Sidekiq signature of scheduled tokens migration
-rw-r--r--db/post_migrate/20181121111200_schedule_runners_token_encryption.rb2
-rw-r--r--lib/gitlab/background_migration/encrypt_runners_tokens.rb10
-rw-r--r--spec/lib/gitlab/background_migration/encrypt_runners_tokens_spec.rb14
-rw-r--r--spec/migrations/schedule_runners_token_encryption_spec.rb7
4 files changed, 23 insertions, 10 deletions
diff --git a/db/post_migrate/20181121111200_schedule_runners_token_encryption.rb b/db/post_migrate/20181121111200_schedule_runners_token_encryption.rb
index 33403610d8e..3a59217f07a 100644
--- a/db/post_migrate/20181121111200_schedule_runners_token_encryption.rb
+++ b/db/post_migrate/20181121111200_schedule_runners_token_encryption.rb
@@ -24,7 +24,7 @@ class ScheduleRunnersTokenEncryption < ActiveRecord::Migration
relation.each_batch(of: RANGE_SIZE) do |relation|
range = relation.pluck('MIN(id)', 'MAX(id)').first
- args = [model, model.encrypted_attributes.keys, *range]
+ args = [model.name.demodulize.downcase, *range]
BackgroundMigrationWorker.perform_in(delay, MIGRATION, args)
end
diff --git a/lib/gitlab/background_migration/encrypt_runners_tokens.rb b/lib/gitlab/background_migration/encrypt_runners_tokens.rb
index 4647301f1a9..cb7a4c4d52e 100644
--- a/lib/gitlab/background_migration/encrypt_runners_tokens.rb
+++ b/lib/gitlab/background_migration/encrypt_runners_tokens.rb
@@ -15,6 +15,14 @@ module Gitlab
#
# https://gitlab.com/gitlab-org/gitlab-ce/issues/54328
#
- class EncryptRunnersTokens < EncryptColumns; end
+ class EncryptRunnersTokens < EncryptColumns
+ def perform(model, from, to)
+ resource = "::Gitlab::BackgroundMigration::Models::EncryptColumns::#{model.to_s.capitalize}"
+ model = resource.constantize
+ attributes = model.encrypted_attributes.keys
+
+ super(model, attributes, from, to)
+ end
+ end
end
end
diff --git a/spec/lib/gitlab/background_migration/encrypt_runners_tokens_spec.rb b/spec/lib/gitlab/background_migration/encrypt_runners_tokens_spec.rb
index b7f2fc73748..fc95f51a822 100644
--- a/spec/lib/gitlab/background_migration/encrypt_runners_tokens_spec.rb
+++ b/spec/lib/gitlab/background_migration/encrypt_runners_tokens_spec.rb
@@ -12,7 +12,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
end
it 'migrates runners registration tokens' do
- migrate!(:settings, :runners_registration_token, 1, 1)
+ migrate!(:settings, 1, 1)
encrypted_token = settings.first.runners_registration_token_encrypted
decrypted_token = ::Gitlab::CryptoHelper.aes256_gcm_decrypt(encrypted_token)
@@ -30,7 +30,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
end
it 'migrates runners registration tokens' do
- migrate!(:namespace, :runners_token, 11, 22)
+ migrate!(:namespace, 11, 22)
expect(namespaces.all.reload).to all(
have_attributes(runners_token: nil, runners_token_encrypted: be_a(String))
@@ -47,7 +47,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
end
it 'migrates runners registration tokens' do
- migrate!(:project, :runners_token, 111, 116)
+ migrate!(:project, 111, 116)
expect(projects.all.reload).to all(
have_attributes(runners_token: nil, runners_token_encrypted: be_a(String))
@@ -63,7 +63,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
end
it 'migrates runners communication tokens' do
- migrate!(:runner, :token, 201, 203)
+ migrate!(:runner, 201, 203)
expect(runners.all.reload).to all(
have_attributes(token: nil, token_encrypted: be_a(String))
@@ -71,9 +71,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
end
end
- def migrate!(model, attribute, from, to)
- model = "::Gitlab::BackgroundMigration::Models::EncryptColumns::#{model.to_s.capitalize}"
-
- subject.perform(model, [attribute], from, to)
+ def migrate!(model, from, to)
+ subject.perform(model, from, to)
end
end
diff --git a/spec/migrations/schedule_runners_token_encryption_spec.rb b/spec/migrations/schedule_runners_token_encryption_spec.rb
index 728220d0a7f..a1e4d36de1c 100644
--- a/spec/migrations/schedule_runners_token_encryption_spec.rb
+++ b/spec/migrations/schedule_runners_token_encryption_spec.rb
@@ -24,6 +24,13 @@ describe ScheduleRunnersTokenEncryption, :migration do
Timecop.freeze do
migrate!
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(2.minutes, 'settings', 1, 1)
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(2.minutes, 'namespace', 11, 11)
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(4.minutes, 'namespace', 12, 12)
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(2.minutes, 'project', 111, 111)
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(4.minutes, 'project', 114, 114)
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(2.minutes, 'runner', 201, 201)
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(4.minutes, 'runner', 202, 202)
expect(BackgroundMigrationWorker.jobs.size).to eq 7
end
end