Commit 23edbcb2 authored by Markus Koller's avatar Markus Koller

Fix argument type for background migration

The arguments to `migrate_in` are splatted and end up as individual
arguments in the background migration, not as an array.

This also creates another post-migration to re-queue the background
migration jobs, and turn the previous post-migration into a noop.
parent 1d19b15c
---
title: Fix argument type for background migration
merge_request: 51475
author:
type: fixed
# frozen_string_literal: true
class RemoveDuplicateServices < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INTERVAL = 2.minutes
BATCH_SIZE = 5_000
MIGRATION = 'RemoveDuplicateServices'
disable_ddl_transaction!
def up
project_ids_with_duplicates = Gitlab::BackgroundMigration::RemoveDuplicateServices::Service.project_ids_with_duplicates
project_ids_with_duplicates.each_batch(of: BATCH_SIZE, column: :project_id) do |batch, index|
migrate_in(
INTERVAL * index,
MIGRATION,
batch.pluck(:project_id)
)
end
# noop, replaced by 20210112143418_remove_duplicate_services.rb
end
def down
......
# frozen_string_literal: true
# This replaces the previous post-deployment migration 20201207165956_remove_duplicate_services_spec.rb,
# we have to run this again due to a bug in how we were receiving the arguments in the background migration.
class RemoveDuplicateServices2 < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INTERVAL = 2.minutes
BATCH_SIZE = 5_000
MIGRATION = 'RemoveDuplicateServices'
disable_ddl_transaction!
def up
project_ids_with_duplicates = Gitlab::BackgroundMigration::RemoveDuplicateServices::Service.project_ids_with_duplicates
project_ids_with_duplicates.each_batch(of: BATCH_SIZE, column: :project_id) do |batch, index|
migrate_in(
INTERVAL * index,
MIGRATION,
batch.pluck(:project_id)
)
end
end
def down
end
end
05d45e25ab9ef1565c04ca6515e0b01f2f98c5e98b1eeb09fa9dd43ebbe3c4d0
\ No newline at end of file
......@@ -29,7 +29,7 @@ module Gitlab
end
end
def perform(project_ids)
def perform(*project_ids)
types_with_duplicates = Service.types_with_duplicates(project_ids).pluck(:project_id, :type)
types_with_duplicates.each do |project_id, type|
......
......@@ -82,7 +82,7 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicateServices, :migration,
end
expect do
subject.perform([project2.id, project3.id])
subject.perform(project2.id, project3.id)
end.to change { services.count }.from(21).to(12)
services1 = services.where(project_id: project1.id)
......@@ -109,13 +109,13 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicateServices, :migration,
it 'does not delete services without duplicates' do
expect do
subject.perform([project1.id, project4.id])
subject.perform(project1.id, project4.id)
end.not_to change { services.count }
end
it 'only deletes duplicate services for the current batch' do
expect do
subject.perform([project2.id])
subject.perform(project2.id)
end.to change { services.count }.by(-3)
end
end
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20201207165956_remove_duplicate_services.rb')
require Rails.root.join('db', 'post_migrate', '20210112143418_remove_duplicate_services2.rb')
RSpec.describe RemoveDuplicateServices do
RSpec.describe RemoveDuplicateServices2 do
let_it_be(:namespaces) { table(:namespaces) }
let_it_be(:projects) { table(:projects) }
let_it_be(:services) { table(:services) }
......
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