Class: PactBroker::DB::DataMigrations::SetPacticipantIdsForVerifications

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

Class Method Summary collapse

Class Method Details

.call(connection) ⇒ Object



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

def self.call connection
  if columns_exist?(connection)
    query = "UPDATE verifications
            SET consumer_id = (SELECT consumer_id
              FROM pact_versions
              WHERE id = verifications.pact_version_id),
             provider_id = (SELECT provider_id
              FROM pact_versions
              WHERE id = verifications.pact_version_id)
            WHERE consumer_id is null
            OR provider_id is null"
    connection.run(query)
  end
end

.column_exists?(connection, table, column) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/pact_broker/db/data_migrations/set_pacticipant_ids_for_verifications.rb', line 31

def self.column_exists?(connection, table, column)
  connection.table_exists?(table) && connection.schema(table).find{|col| col.first == column }
end

.columns_exist?(connection) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.columns_exist?(connection)
  column_exists?(connection, :verifications, :provider_id) &&
    column_exists?(connection, :verifications, :consumer_id) &&
    column_exists?(connection, :verifications, :provider_version_id) &&
    column_exists?(connection, :pact_versions, :provider_id) &&
    column_exists?(connection, :pact_versions, :consumer_id) &&
    column_exists?(connection, :pact_versions, :id)
end