Sha256: a87698470e8bda135c6eab7f49b59f71d26ec2e479a984a10a277b9cc5bed50e

Contents?: true

Size: 1.11 KB

Versions: 55

Compression:

Stored size: 1.11 KB

Contents

require 'pact_broker/db/data_migrations/helpers'

module PactBroker
  module DB
    module DataMigrations
      class MigrateWebhookHeaders
        extend Helpers

        def self.call(connection)
          if columns_exist?(connection)
            connection[:webhook_headers].for_update.each do | webhook_header |
              webhook = connection[:webhooks].for_update.where(id: webhook_header[:webhook_id]).first
              new_headers = webhook[:headers] ? JSON.parse(webhook[:headers]) : {}
              new_headers[webhook_header[:name]] = webhook_header[:value]
              connection[:webhooks].where(id: webhook[:id]).update(headers: new_headers.to_json)
              connection[:webhook_headers].where(webhook_header).delete
            end
          end
        end

        def self.columns_exist?(connection)
          column_exists?(connection, :webhooks, :headers) &&
            column_exists?(connection, :webhook_headers, :name) &&
            column_exists?(connection, :webhook_headers, :value) &&
            column_exists?(connection, :webhook_headers, :webhook_id)
        end
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
pact_broker-2.79.1 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.79.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.78.1 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.78.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.77.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.76.2 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.76.1 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.76.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.75.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.74.1 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.74.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.73.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.72.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.71.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.70.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.69.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.68.1 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.68.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.67.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
pact_broker-2.66.0 lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb