Sha256: e8abdabbda9936dd0d48ffa3b1f4757f2fdf5603a486999eec316f57ce8676b8

Contents?: true

Size: 1.43 KB

Versions: 44

Compression:

Stored size: 1.43 KB

Contents

require "securerandom"

Sequel.migration do
  up do
    from(:webhook_executions).each do | execution |
      pact_publication = from(:all_pact_publications).where(
        consumer_id: execution[:consumer_id],
        provider_id: execution[:provider_id]
      ).where(
        Sequel.lit("created_at <= ?", execution[:created_at])
      ).reverse_order(:id).limit(1).single_record

      if pact_publication && execution[:webhook_id]
        webhook = from(:webhooks).where(id: execution[:webhook_id]).single_record

        if webhook
          webhook_uuid = webhook[:uuid]
          status = execution[:success] ? "success" : "failure"

          from(:triggered_webhooks).insert(
            trigger_uuid: SecureRandom.urlsafe_base64,
            trigger_type: "pact_publication",
            pact_publication_id: pact_publication[:id],
            webhook_id: execution[:webhook_id],
            webhook_uuid: webhook_uuid,
            consumer_id: execution[:consumer_id],
            provider_id: execution[:provider_id],
            created_at: execution[:created_at],
            updated_at: execution[:created_at],
            status: status
          )
        end
      end
      from(:webhook_executions)
        .where(id: execution[:id])
        .update(
          webhook_id: nil,
          consumer_id: nil,
          provider_id: nil,
          pact_publication_id: nil)
    end
  end

  down do
    from(:triggered_webhooks).delete
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

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