Commit 4dc48bc2 authored by Stan Hu's avatar Stan Hu

Merge branch 'sh-background-migration-double-parsing' into 'master'

Fix null argument handling in background migration Rake task

See merge request gitlab-org/gitlab!84318
parents a9bc2aa9 b6f60ccc
...@@ -961,7 +961,7 @@ module Gitlab ...@@ -961,7 +961,7 @@ module Gitlab
"\n\n" \ "\n\n" \
"Finalize it manualy by running" \ "Finalize it manualy by running" \
"\n\n" \ "\n\n" \
"\tsudo gitlab-rake gitlab:background_migrations:finalize[#{job_class_name},#{table_name},#{column_name},'#{job_arguments.inspect.gsub(',', '\,')}']" \ "\tsudo gitlab-rake gitlab:background_migrations:finalize[#{job_class_name},#{table_name},#{column_name},'#{job_arguments.to_json.gsub(',', '\,')}']" \
"\n\n" \ "\n\n" \
"For more information, check the documentation" \ "For more information, check the documentation" \
"\n\n" \ "\n\n" \
......
...@@ -19,7 +19,7 @@ namespace :gitlab do ...@@ -19,7 +19,7 @@ namespace :gitlab do
args[:job_class_name], args[:job_class_name],
args[:table_name], args[:table_name],
args[:column_name], args[:column_name],
Gitlab::Json.parse(args[:job_arguments]), args[:job_arguments],
connection: main_model.connection connection: main_model.connection
) )
end end
...@@ -38,7 +38,7 @@ namespace :gitlab do ...@@ -38,7 +38,7 @@ namespace :gitlab do
args[:job_class_name], args[:job_class_name],
args[:table_name], args[:table_name],
args[:column_name], args[:column_name],
Gitlab::Json.parse(args[:job_arguments]), args[:job_arguments],
connection: model.connection connection: model.connection
) )
end end
......
...@@ -2211,7 +2211,7 @@ RSpec.describe Gitlab::Database::MigrationHelpers do ...@@ -2211,7 +2211,7 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
job_class_name: 'CopyColumnUsingBackgroundMigrationJob', job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
table_name: :events, table_name: :events,
column_name: :id, column_name: :id,
job_arguments: [["id"], ["id_convert_to_bigint"]] job_arguments: [["id"], ["id_convert_to_bigint"], nil]
} }
end end
...@@ -2226,7 +2226,7 @@ RSpec.describe Gitlab::Database::MigrationHelpers do ...@@ -2226,7 +2226,7 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
"\n\n" \ "\n\n" \
"Finalize it manualy by running" \ "Finalize it manualy by running" \
"\n\n" \ "\n\n" \
"\tsudo gitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,events,id,'[[\"id\"]\\, [\"id_convert_to_bigint\"]]']" \ "\tsudo gitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,events,id,'[[\"id\"]\\,[\"id_convert_to_bigint\"]\\,null]']" \
"\n\n" \ "\n\n" \
"For more information, check the documentation" \ "For more information, check the documentation" \
"\n\n" \ "\n\n" \
......
...@@ -42,6 +42,17 @@ RSpec.describe 'gitlab:background_migrations namespace rake tasks' do ...@@ -42,6 +42,17 @@ RSpec.describe 'gitlab:background_migrations namespace rake tasks' do
end end
end end
context 'with a null parameter' do
let(:arguments) { %w[ProjectNamespaces::BackfillProjectNamespaces projects id] + ['[null\, "up"]'] }
it 'finalizes the matching migration' do
expect(Gitlab::Database::BackgroundMigration::BatchedMigrationRunner).to receive(:finalize)
.with('ProjectNamespaces::BackfillProjectNamespaces', 'projects', 'id', [nil, "up"], connection: connection)
expect { finalize_task }.to output(/Done/).to_stdout
end
end
context 'when multiple database feature is enabled' do context 'when multiple database feature is enabled' do
subject(:finalize_task) { run_rake_task("gitlab:background_migrations:finalize:#{ci_database_name}", *arguments) } subject(:finalize_task) { run_rake_task("gitlab:background_migrations:finalize:#{ci_database_name}", *arguments) }
......
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