Skip to content

Commit

Permalink
Allow the events table to work with integer based aggregates
Browse files Browse the repository at this point in the history
  • Loading branch information
LostKobrakai committed Sep 10, 2020
1 parent 857c007 commit 040c421
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/fable/migrations.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
defmodule Fable.Migrations do
use Ecto.Migration

def events_table(table) do
def events_table(table, opts \\ []) do
aggregate_type = Keyword.get(opts, :aggregate_type, :uuid)

create table(table, primary_key: false) do
add(:id, :bigserial, primary_key: true)
add(:prev_event_id, :integer)
add(:aggregate_id, :uuid, null: false)
add(:aggregate_id, aggregate_type, null: false)
add(:aggregate_table, :string, null: false)
add(:type, :string, null: false)
add(:version, :integer, null: false)
Expand All @@ -24,7 +26,7 @@ defmodule Fable.Migrations do
as $$
DECLARE
rcount int;
result uuid;
result #{aggregate_type};
find_aggregate text := format(
'SELECT id FROM %I WHERE id = $1', NEW.aggregate_table
);
Expand Down

0 comments on commit 040c421

Please sign in to comment.