Support overriding batch column for dynamic models
What does this MR do and why?
Related to #408168 (closed)
Gitlab::Database::DynamicModelHelpers
provides two methods that wrap each_batch
for use in DB migrations and this MR updates both of the two methods.
- Update 1. Support specifying a custom column to batch over.
each_batch
supports specifying a custom column like this:
Issue.each_batch(of: 100, column: :created_at) do |batch|
puts batch.pick("MIN(created_at), MAX(created_at)")
end
However, the wrapper each_batch
defined in Gitlab::Database::DynamicModelHelpers
did not support specifying a column.
- Update 2. Fix
each_batch_range
to correctly pick out the primary key of the batch table.
NamespaceSettings
's primary key is namespace_id
. Using each_batch_range
on the table would not yield the correct primary key columns.
- See !118581 (comment 1366429019)
- We actually had a problem in !114423 (comment 1359877440).
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by euko