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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe RemoveLeftoverCiJobArtifactDeletions, feature_category: :sharding do
let(:deleted_records) { table(:loose_foreign_keys_deleted_records) }
target_table_name = Ci::JobArtifact.table_name
let(:pending_record1) do
deleted_records.create!(
id: 1,
fully_qualified_table_name: "public.#{target_table_name}",
primary_key_value: 1,
status: 1
)
end
let(:pending_record2) do
deleted_records.create!(
id: 2,
fully_qualified_table_name: "public.#{target_table_name}",
primary_key_value: 2,
status: 1
)
end
let(:other_pending_record1) do
deleted_records.create!(
id: 3,
fully_qualified_table_name: 'public.projects',
primary_key_value: 1,
status: 1
)
end
let(:other_pending_record2) do
deleted_records.create!(
id: 4,
fully_qualified_table_name: 'public.ci_builds',
primary_key_value: 1,
status: 1
)
end
let(:processed_record1) do
deleted_records.create!(
id: 5,
fully_qualified_table_name: 'public.external_pull_requests',
primary_key_value: 3,
status: 2
)
end
let(:other_processed_record1) do
deleted_records.create!(
id: 6,
fully_qualified_table_name: 'public.ci_builds',
primary_key_value: 2,
status: 2
)
end
let!(:persisted_ids_before) do
[
pending_record1,
pending_record2,
other_pending_record1,
other_pending_record2,
processed_record1,
other_processed_record1
].map(&:id).sort
end
let!(:persisted_ids_after) do
[
other_pending_record1,
other_pending_record2,
processed_record1,
other_processed_record1
].map(&:id).sort
end
def all_ids
deleted_records.all.map(&:id).sort
end
it 'deletes pending external_pull_requests records' do
expect { migrate! }.to change { all_ids }.from(persisted_ids_before).to(persisted_ids_after)
end
end
|