Skip to content
DBML templates

DBML — event sourcing skeleton

Aggregate, events, and snapshot tables.

Template previewDBML
events.aggregate_id > aggregates.idsnapshots.aggregate_id > aggregates.idaggregatesiduuidtypevarcharversioninteventsidbigintaggregate_iduuidversioninttypevarcharpayloadjsonboccurred_attimestampsnapshotsaggregate_iduuidversionintstatejsonbtaken_attimestamp

Make it your own.

Table aggregates {
  id uuid [pk]
  type varchar
  version int
}
Table events {
  id bigint [pk, increment]
  aggregate_id uuid [ref: > aggregates.id]
  version int
  type varchar
  payload jsonb
  occurred_at timestamp
}
Table snapshots {
  aggregate_id uuid [pk, ref: > aggregates.id]
  version int
  state jsonb
  taken_at timestamp
}