Commit ac515aa1 authored by George Koltsov's avatar George Koltsov

Reorder exported relations by primary_key

parent 64cedf39
---
title: Reorder exported relations by primary_key when using Project Export
merge_request: 27117
author:
type: fixed
......@@ -136,6 +136,12 @@ module Gitlab
data = []
record.in_batches(of: @batch_size) do |batch| # rubocop:disable Cop/InBatches
# order each batch by it's primary key to ensure
# consistent and predictable ordering of each exported relation
# as additional `WHERE` clauses can impact the order in which data is being
# returned by database when no `ORDER` is specified
batch = batch.reorder(batch.klass.primary_key)
if Feature.enabled?(:export_fast_serialize_with_raw_json, default_enabled: true)
data.append(JSONBatchRelation.new(batch, options, preloads[key]).tap(&:raw_json))
else
......
......@@ -215,6 +215,14 @@ describe Gitlab::ImportExport::FastHashSerializer do
expect(subject['boards'].first['lists']).not_to be_empty
end
context 'relation ordering' do
it 'orders exported pipelines by primary key' do
expected_order = project.ci_pipelines.reorder(:id).ids
expect(subject['ci_pipelines'].pluck('id')).to eq(expected_order)
end
end
def setup_project
release = create(:release)
group = create(:group)
......@@ -246,6 +254,8 @@ describe Gitlab::ImportExport::FastHashSerializer do
ci_build.pipeline.update(project: project)
create(:commit_status, project: project, pipeline: ci_build.pipeline)
create_list(:ci_pipeline, 5, :success, project: project)
create(:milestone, project: project)
create(:discussion_note, noteable: issue, project: project)
create(:note, noteable: merge_request, project: project)
......
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