From 61767b40c2bf57edec92d3b2aa300ad9cca3db99 Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad Date: Mon, 19 Aug 2024 11:06:17 +0300 Subject: [PATCH] Adds metadata to outboxes --- lib/outboxable.rb | 7 ++++++- lib/templates/create_outboxable_outboxes.rb | 1 + lib/templates/mongoid_outbox.rb | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/outboxable.rb b/lib/outboxable.rb index 886aa6f..31871aa 100644 --- a/lib/outboxable.rb +++ b/lib/outboxable.rb @@ -27,7 +27,12 @@ module Outboxable outboxes.new( routing_key:, exchange: Outboxable.configuration.rabbitmq_exchange_name, - payload: as_json + payload: as_json, + metadata: if respond_to?(:metadata_for_outbox) + metadata_for_outbox + else + {} + end ) end diff --git a/lib/templates/create_outboxable_outboxes.rb b/lib/templates/create_outboxable_outboxes.rb index 02a6e7b..2d83c39 100644 --- a/lib/templates/create_outboxable_outboxes.rb +++ b/lib/templates/create_outboxable_outboxes.rb @@ -15,6 +15,7 @@ class CreateOutboxableOutboxes < ActiveRecord::Migration[7.0] t.jsonb :payload, default: {} t.jsonb :headers, default: {} + t.jsonb :metadata, default: {}, null: true t.integer :size, null: false, default: 0 diff --git a/lib/templates/mongoid_outbox.rb b/lib/templates/mongoid_outbox.rb index cbe3dd7..1ae4da9 100644 --- a/lib/templates/mongoid_outbox.rb +++ b/lib/templates/mongoid_outbox.rb @@ -22,6 +22,7 @@ class Outbox field :payload, type: Hash, default: {} field :headers, type: Hash, default: {} + field :metadata, type: Hash, default: {} index({ idempotency_key: 1 }, { unique: true, name: 'idempotency_key_unique_index' })