Class: PactBroker::DB::DataMigrations::SetConsumerVersionOrderForPactPublications

Inherits:
Object
  • Object
show all
Extended by:
Helpers
Defined in:
lib/pact_broker/db/data_migrations/set_consumer_version_order_for_pact_publications.rb

Class Method Summary collapse

Methods included from Helpers

column_exists?, columns_exist?

Class Method Details

.call(connection) ⇒ Object



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

def self.call connection
  if required_columns_exist?(connection)
    connection.from(:pact_publications)
      .where(consumer_version_order: nil)
      .update(
        consumer_version_order: connection.from(:versions)
          .select(:order)
          .where(Sequel[:versions][:id] => Sequel[:pact_publications][:consumer_version_id])
      )
  end
end

.required_columns_exist?(connection) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/pact_broker/db/data_migrations/set_consumer_version_order_for_pact_publications.rb', line 21

def self.required_columns_exist?(connection)
  columns_exist?(connection, :pact_publications, [:consumer_version_id, :consumer_version_order]) &&
    columns_exist?(connection, :versions, [:id, :order])
end