Class: PactBroker::DB::DataMigrations::SetContractDataUpdatedAtForIntegrations

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/db/data_migrations/set_contract_data_updated_at_for_integrations.rb

Class Method Summary collapse

Class Method Details

.call(connection) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/pact_broker/db/data_migrations/set_contract_data_updated_at_for_integrations.rb', line 7

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

.integrations_max_created_at(connection) ⇒ Sequel::Dataset

for each integration keyed by consumer_id/provider_id

Returns:

  • (Sequel::Dataset)

    the overall max created_at from the union of the pact_publications and verifications tables,



22
23
24
25
26
27
# File 'lib/pact_broker/db/data_migrations/set_contract_data_updated_at_for_integrations.rb', line 22

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

.pact_publication_max_created_at(connection) ⇒ Sequel::Dataset

for each integration keyed by consumer_id/provider_id

Returns:

  • (Sequel::Dataset)

    the max created_at from the pact_publications table



31
32
33
34
35
# File 'lib/pact_broker/db/data_migrations/set_contract_data_updated_at_for_integrations.rb', line 31

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

.verification_max_created_at(connection) ⇒ Sequel::Dataset

for each integration keyed by consumer_id/provider_id

Returns:

  • (Sequel::Dataset)

    the max created_at from the verifications table



39
40
41
42
43
# File 'lib/pact_broker/db/data_migrations/set_contract_data_updated_at_for_integrations.rb', line 39

def self.verification_max_created_at(connection)
  connection[:verifications]
    .select_group(:consumer_id, :provider_id)
    .select_append{ max(:created_at).as(:created_at) }
end