Commit 1143411a authored by Grzegorz Bizon's avatar Grzegorz Bizon

Reduce Sidekiq signature of scheduled tokens migration

parent 627b4833
......@@ -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
......
......@@ -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
......@@ -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
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment