Partitioning data migration for web_hook_logs fails
Summary
On 13.11.3, a customer noticed in ZD (internal only) that migrations fail with:
web_hook_logs has composite primary key. Composite primary key is ignored.
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
the column: argument must be set to a column name to use for ordering rows
/opt/gitlab/embedded/service/gitlab-rails/app/models/concerns/each_batch.rb:52:in `each_batch'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migrations/background_migration_helpers.rb:109:in `queue_background_migration_jobs_by_range_at_intervals'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/partitioning_migration_helpers/table_management_helpers.rb:395:in `enqueue_background_migration'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/partitioning_migration_helpers/table_management_helpers.rb:108:in `enqueue_partitioning_data_migration'
/opt/gitlab/embedded/service/gitlab-rails/db/post_migrate/20210306121310_backfill_partitioned_web_hook_logs.rb:11:in `up'
The table seems as ~expected:
Partitioned table "public.web_hook_logs"
[..]
Partition key: RANGE (created_at)
Indexes:
"web_hook_logs_pkey" PRIMARY KEY, btree (id, created_at)
"index_web_hook_logs_part_on_created_at_and_web_hook_id" btree (created_at, web_hook_id)
"index_web_hook_logs_part_on_web_hook_id" btree (web_hook_id)
Steps to reproduce
Not sure yet - trying to. @abrandl mentioned he can sort of reproduce:
[1] pry(main)> ActiveRecord::Base.connection.primary_key(:web_hook_logs)
=> ["id", "created_at"]
[2] pry(main)> include Gitlab::Database::DynamicModelHelpers
=> Object
[3] pry(main)> model = define_batchable_model(:web_hook_logs)
=> #<Class:0x000055bc9646d888>(id: integer, web_hook_id: integer, trigger: string, url: string, request_headers: text, request_data: text, response_headers: text, response_body: text, response_status: string, execution_duration: float, internal_error_message: string, updated_at: datetime, created_at: datetime)
[4] pry(main)> model.primary_key
WARNING: Active Record does not support composite primary key.
web_hook_logs has composite primary key. Composite primary key is ignored.
=> nil
[6] pry(main)> model.each_batch(of: 100) { |b| puts b }
ArgumentError: the column: argument must be set to a column name to use for ordering rows
from /home/abrandl/workspace/gdk/gitlab/app/models/concerns/each_batch.rb:52:in `each_batch'
What is the current bug behavior?
Migrations fail.
What is the expected correct behavior?
The partitioning data migration should be enqueued as expected