Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20210406144743_backfill_total_tuple_count_for_batched_migrations_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 18aa8e92560ea3ab1d79cb2693c1e7a0076ad70f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

require 'spec_helper'
require_migration!

RSpec.describe BackfillTotalTupleCountForBatchedMigrations, :migration, schema: 20210406140057,
                                                                        feature_category: :database do
  let!(:table_name) { 'projects' }

  let!(:migrations) { table(:batched_background_migrations) }

  let!(:migration) do
    migrations.create!(
      created_at: Time.now,
      updated_at: Time.now,
      min_value: 1,
      max_value: 10_000,
      batch_size: 1_000,
      sub_batch_size: 100,
      interval: 120,
      status: 0,
      job_class_name: 'Foo',
      table_name: table_name,
      column_name: :id,
      total_tuple_count: nil
    )
  end

  describe '#up' do
    before do
      expect(Gitlab::Database::PgClass).to receive(:for_table).with(table_name).and_return(estimate)
    end

    let(:estimate) { double('estimate', cardinality_estimate: 42) }

    it 'updates total_tuple_count attribute' do
      migrate!

      migrations.all.each do |migration|
        expect(migration.total_tuple_count).to eq(estimate.cardinality_estimate)
      end
    end
  end
end