-
-
Notifications
You must be signed in to change notification settings - Fork 171
/
set_contract_data_updated_at_for_integrations.rb
47 lines (42 loc) · 2.07 KB
/
set_contract_data_updated_at_for_integrations.rb
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
# Populate the newly created contract_data_updated_at date in the integrations table
# using the latest created_at date from the pact_publications or verifications tables.
module PactBroker
module DB
module DataMigrations
class SetContractDataUpdatedAtForIntegrations
def self.call(connection)
join = {
Sequel[:integrations][:consumer_id] => Sequel[:target][:consumer_id],
Sequel[:integrations][:provider_id] => Sequel[:target][:provider_id]
}
max_created_at_for_each_integration = integrations_max_created_at(connection).from_self(alias: :target).select(:created_at).where(join)
connection[:integrations]
.where(contract_data_updated_at: nil)
.update(contract_data_updated_at: max_created_at_for_each_integration)
end
# @return [Sequel::Dataset] the overall max created_at from the union of the pact_publications and verifications tables,
# for each integration keyed by consumer_id/provider_id
def self.integrations_max_created_at(connection)
pact_publication_max_created_at(connection)
.union(verification_max_created_at(connection))
.select_group(:consumer_id, :provider_id)
.select_append{ max(:created_at).as(:created_at) }
end
# @return [Sequel::Dataset] the max created_at from the pact_publications table
# for each integration keyed by consumer_id/provider_id
def self.pact_publication_max_created_at(connection)
connection[:pact_publications]
.select_group(:consumer_id, :provider_id)
.select_append{ max(:created_at).as(:created_at) }
end
# @return [Sequel::Dataset] the max created_at from the verifications table
# for each integration keyed by consumer_id/provider_id
def self.verification_max_created_at(connection)
connection[:verifications]
.select_group(:consumer_id, :provider_id)
.select_append{ max(:created_at).as(:created_at) }
end
end
end
end
end