Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

### Added

- Allow to set the `last_transaction_id` when outbox is created

## [0.15.2] - 2025-07-15

### Added
Expand Down
13 changes: 10 additions & 3 deletions lib/carbonite/migrations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -261,28 +261,33 @@ defmodule Carbonite.Migrations do
# ------------------------------- outbox setup -----------------------------------

@type outbox_name :: String.t()
@type outbox_option :: {:carbonite_prefix, prefix()}
@type create_outbox_option ::
{:carbonite_prefix, prefix()} | {:last_transaction_id, non_neg_integer()}

@doc """
Inserts an outbox record into the database.

## Options

* `carbonite_prefix` is the schema of the audit trail, defaults to `"carbonite_default"`
* `last_transaction_id` allows to start the outbox processing *after* the given transaction id
"""
@doc since: "0.4.0"
@spec create_outbox(outbox_name()) :: :ok
@spec create_outbox(outbox_name(), [outbox_option()]) :: :ok
@spec create_outbox(outbox_name(), [create_outbox_option()]) :: :ok
def create_outbox(outbox_name, opts \\ []) do
carbonite_prefix = Keyword.get(opts, :carbonite_prefix, default_prefix())
last_transaction_id = Keyword.get(opts, :last_transaction_id, "DEFAULT")

"""
INSERT INTO #{carbonite_prefix}.outboxes (
name,
last_transaction_id,
inserted_at,
updated_at
) VALUES (
'#{outbox_name}',
#{last_transaction_id},
NOW(),
NOW()
);
Expand All @@ -292,6 +297,8 @@ defmodule Carbonite.Migrations do
:ok
end

@type drop_outbox_option :: {:carbonite_prefix, prefix()}

@doc """
Removes an outbox record.

Expand All @@ -301,7 +308,7 @@ defmodule Carbonite.Migrations do
"""
@doc since: "0.4.0"
@spec drop_outbox(outbox_name()) :: :ok
@spec drop_outbox(outbox_name(), [outbox_option()]) :: :ok
@spec drop_outbox(outbox_name(), [drop_outbox_option()]) :: :ok
def drop_outbox(outbox_name, opts \\ []) do
carbonite_prefix = Keyword.get(opts, :carbonite_prefix, default_prefix())

Expand Down