将旧版数据库迁移到CQR/事件源视图 [英] Migrate legacy database to cqrs/event sourcing view

查看:63
本文介绍了将旧版数据库迁移到CQR/事件源视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有具有复杂业务逻辑的旧版旧版应用程序,需要对其进行重写.我们考虑使用cqrs和事件源.但是尚不清楚如何从旧数据库迁移数据.可能我们只需要将其迁移到读取数据库中,因为我们无法复制所有事件来填充事件存储.但是我们至少需要在事件存储中为每个聚合创建一些初始记录,例如 AggregateCreated 吗?还是我们需要编写脚本并使用所有命令一个接一个地使用所有命令来以通常与事件源相同的方式重新创建聚合?

We got old legacy application with complex business logic which we need to rewrite. We consider to use cqrs and event sourcing. But it's not clear how to migrate data from the old database. Probable we need migrate it to the read database only, as we can't reproduce all the events to populate event store. But we atleast need to create some initial records in event store for each aggregate, like AggregateCreated? Or we need write a scripts and to use all the commands one by one to recreate aggregates in same way we will normally with event sourcing?

推荐答案

使用现有数据库或其转换版本作为开始读取侧持久性从来都不是一个好主意.您的事件源系统需要开始,因此您将获得事件源的主要好处之一-能够使用多语言持久性按需创建投影.

Using the existing database, or a transformed version of it, as a start of your read-side persistence is never a good idea. Your event-sourced system needs to have its start, so you get one of the main benefits of event sourcing - being able to create projections on-demand, using polyglot persistence.

使用命令进行迁移也不是一个好主意,原因很简单,因为根据定义,命令可能会由于对不变控制的条件检查或事后检查而失败.它还没有传达迁移的含义,它表示当前的系统状态.请记住,当前的系统状态不是您可以接受或拒绝的.它是给您的,您的工作就是捕获它.

Using commands for migration is also not a good idea for a simple reason that commands, by definition, can fail due to pre or post-condition check of invariant control. It also does not convey the meaning of migration, which is to represent the current system state as it is right now. Remember, that the current system stay is not something you can accept or deny. It is given to you and your job is to capture it.

这种迁移的最佳实践是发出所谓的迁移事件,例如 EntityXMigratedFromLegacy .当然,这项工作可能会很艰巨.主要是因为旧系统模型很可能与新模型不匹配,否则这种迁移的原因尚不完全清楚.

The best practice for such a migration is to emit so-called migration events, like EntityXMigratedFromLegacy. Of course, the work might be substantial. Mainly because the legacy system model will most probably not match the new model, otherwise the reason for such a migration isn't entirely clear.

通过使用迁移事件,您可以明确声明一个状态原样从另一个地方移开的事实.您将永远知道被迁移的实体如何在新系统中开始其生命周期-通过从旧版迁移或通过在新系统中初始化来实现.

By using migration events you explicitly state the fact that a piece of state was moved from another place, as-is. You will always know how the migrated entity started its lifecycle in the new system - either by being migrated from legacy or by being initialised in the new system.

这篇关于将旧版数据库迁移到CQR/事件源视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆