postgresql – 事件源的关系数据库模式

我试图将域事件存储在postgres数据库中.我在很多方面都不确定,我不想在以后重新设计这个结构,所以我正在寻找具有事件采购经验的人的指导.我目前有下表:
domain events
    version - or event id,integer sequence,helps to maintain order by replays
    type - event type,probably classname with namespace
    aggregate - aggregate id,probably random string for each aggregate
    timestamp - when the event occured
    promoter - the promoter of the event,probably user id
    details - json encoded data about the properties

我不确定的是什么:

>我应该存储域事件的启动器吗?
它可能有助于找到安全漏洞导致的受损帐户,但是
我不知道如何通过CRONjob存储什么.
>我应该以什么格式存储事件类型?
我应该添加一个包含事件类型的表,还是类名呢?
我应该添加活动组吗?
>我对有界上下文的定义感到困惑.据我所知,每个聚合都可以有多个有界上下文,因此我可以在多个模块中使用单个聚合的不同方面.这听起来不错,因为例如帐户可以与许多事情相关,包括身份验证,授权,用户配置文件,用户帖子,用户合同等等……
我不确定的是,域事件可以有多个有界上下文,或者只有一个,所以我也应该存储事件上下文吗? (对于我想重播与单个上下文相关的事件的情况)
如何在单个聚合类中实现这么多属性,我应该使用某种组合吗?

1.Should I store the promoter of the domain event?

如果您将启动器存储为事件有效负载的一部分而不是元数据,我认为它更灵活.应该在域外处理安全问题.并非每个事件都是由用户引发的,尽管您可以为它们制作一个假的(CysJob的SysAdmin).

例如:

ManualPaymentMadeEvent { //store this object as details in your schema
    amount,by_user//In this case,developers can determine whether store the promoter case by case
}

2.what format should I store the event type?
Should I add a table with event types,or are the class names enough?
Should I add event groups?

我认为课程名称就足够了.添加一个表使事件读取变得复杂(通过连接表),我认为它只在重命名类名时添加值(在事件类型表中更新一行).但我认为使用它不会增加太多麻烦

update domain_events set 
    aggregate_type = 'new class name'
where aggregate_type = 'origin class name'

我不确定我是否了解事件组,您能否添加更多解释?

3.What I am unsure,that a domain event can have multiple bounded contexts,or just a single one,so should I store event contexts as
well?

有时,事件用于集成多个上下文.但每个事件仅在一个上下文中引发.例如,在订购上下文中引发了ManualPaymentMadeEvent,并且运输上下文中的事件列表器也使用它,将其视为开始发货的触发器.

我更喜欢每个上下文使用每个数据库用户(oracle术语). shipping.domain_events用于发货上下文和ordering.domain_events用于订购上下文.

这是axon-framework中可能有用的架构

create table DomainEventEntry (
    aggregateIdentifier varchar2(255) not null,sequenceNumber number(19,0) not null,type varchar2(255) not null,--aggregate class name
    eventIdentifier varchar2(255) not null,MetaData blob,payload blob not null,-- details
    payloadRevision varchar2(255),payloadType varchar2(255) not null,--event class name
    timeStamp varchar2(255) not null
);

alter table DomainEventEntry
    add constraint PK_DomainEventEntry primary key (aggregateIdentifier,sequenceNumber,type);

相关文章

项目需要,有个数据需要导入,拿到手一开始以为是mysql,结果...
本文小编为大家详细介绍“怎么查看PostgreSQL数据库中所有表...
错误现象问题原因这是在远程连接时pg_hba.conf文件没有配置正...
因本地资源有限,在公共测试环境搭建了PGsql环境,从数据库本...
wamp 环境 这个提示就是说你的版本低于10了。 先打印ph...
psycopg2.OperationalError: SSL SYSCALL error: EOF detect...