Skip to content

Commit 0e12dc3

Browse files
committed
Allow the events table to work with integer based aggregates
1 parent 2e542e6 commit 0e12dc3

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

lib/fable/migrations.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
defmodule Fable.Migrations do
22
use Ecto.Migration
33

4-
def events_table(table) do
4+
def events_table(table, opts \\ []) do
5+
aggregate_type = Keyword.get(opts, :aggregate_type, :uuid)
6+
57
create table(table, primary_key: false) do
68
add(:id, :bigserial, primary_key: true)
79
add(:prev_event_id, :integer)
8-
add(:aggregate_id, :uuid, null: false)
10+
add(:aggregate_id, aggregate_type, null: false)
911
add(:aggregate_table, :string, null: false)
1012
add(:type, :string, null: false)
1113
add(:version, :integer, null: false)
@@ -24,7 +26,7 @@ defmodule Fable.Migrations do
2426
as $$
2527
DECLARE
2628
rcount int;
27-
result uuid;
29+
result #{aggregate_type};
2830
find_aggregate text := format(
2931
'SELECT id FROM %I WHERE id = $1', NEW.aggregate_table
3032
);

0 commit comments

Comments
 (0)