Sha256: 38bb6eb75cce97bb176d2dacbc45ba0d100d74d9e294071f6105d783264cab17

Contents?: true

Size: 1.79 KB

Versions: 32

Compression:

Stored size: 1.79 KB

Contents

require "pact_broker/db/data_migrations/helpers"

module PactBroker
  module DB
    module DataMigrations
      class MigrateIntegrations
        extend Helpers

        def self.call(connection)
          self_join = {
            Sequel[:pact_publications][:consumer_id] => Sequel[:existing_integrations][:consumer_id],
            Sequel[:pact_publications][:provider_id] => Sequel[:existing_integrations][:provider_id]
          }

          missing_integrations = connection
                                  .from(:pact_publications)
                                    .select(
                                      Sequel[:pact_publications][:consumer_id],
                                      Sequel[:consumer][:name].as(:consumer_name),
                                      Sequel[:pact_publications][:provider_id],
                                      Sequel[:provider][:name].as(:provider_name),
                                      Sequel[:consumer][:created_at]
                                    )
                                    .distinct
                                    .left_outer_join(:integrations, self_join, { :table_alias => :existing_integrations })
                                    .join(:pacticipants, { :id => :consumer_id }, { :table_alias => :consumer, implicit_qualifier: :pact_publications })
                                    .join(:pacticipants, { :id => :provider_id }, { :table_alias => :provider, implicit_qualifier: :pact_publications })
                                    .where(Sequel[:existing_integrations][:provider_id] => nil)

          connection
            .from(:integrations)
            .insert(
            [:consumer_id, :consumer_name, :provider_id, :provider_name, :created_at],
            missing_integrations
          )
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
pact_broker-2.112.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.111.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.109.1 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.109.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.108.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.107.1 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.107.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.106.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.105.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.104.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.103.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.102.2 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.102.1 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.102.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.101.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.100.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.99.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.98.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb
pact_broker-2.97.0 lib/pact_broker/db/data_migrations/migrate_integrations.rb