如何使用 dynamodb table 设计来证明这些可能的需求变化(交换主键列)?
How to future proof these possible requirement changes (swaping primary key columns) with a dynamodb table design?
我有如下数据结构
item_id String
version String
_id String
data String
_id
只是一个用于标识项目的 UUID。目前还不需要按该字段搜索行。
目前,item_id,一个由外部系统生成的id,是一个主键。即给定 item_id,我希望能够从 dynamodb table.
检索 version
、_id
和 data
item_id -> (version, _id, data)
因此我将 item_id
设置为分区键。
我有两个关于上述“模式”的未来验证(演变)的问题:
以后如果我想把version(item的版本号)合并到主键里,只需要修改table,把它加到partition key上就可以了?
如果我也想通过_id
搜索数据,是否可行修改table分配_id
作为分区键(它是一个唯一值,因为它是一个 UUID)并重新分配 item_id
为搜索键?
我想避免创建新的 dynamodb table 和数据迁移以创建新的密钥结构,因为这可能会导致停机。
您无法更新 DynamoDB 中的主键。来自 docs:
You cannot use UpdateItem to update any primary key attributes. Instead, you will need to delete the item, and then use PutItem to create a new item with new attributes.
如果你想让数据可以被 _id
搜索到,你可以引入一个 secondary index 并且 _id
字段作为索引的分区键。
例如,假设您的数据如下所示:
如果您在 _id
上定义了二级索引,索引将如下所示(与上一个示例相同的数据,只是不同的逻辑视图):
DynamoDB 目前没有任何本机版本控制功能,因此您必须将其合并到您的数据模型中。幸运的是,网络上有很多关于此用例的讨论。 AWS 有一份 DynamoDB“最佳实践”文档,其中包括 example of versioning.
我有如下数据结构
item_id String
version String
_id String
data String
_id
只是一个用于标识项目的 UUID。目前还不需要按该字段搜索行。
目前,item_id,一个由外部系统生成的id,是一个主键。即给定 item_id,我希望能够从 dynamodb table.
检索version
、_id
和 data
item_id -> (version, _id, data)
因此我将 item_id
设置为分区键。
我有两个关于上述“模式”的未来验证(演变)的问题:
以后如果我想把version(item的版本号)合并到主键里,只需要修改table,把它加到partition key上就可以了?
如果我也想通过
_id
搜索数据,是否可行修改table分配_id
作为分区键(它是一个唯一值,因为它是一个 UUID)并重新分配item_id
为搜索键?
我想避免创建新的 dynamodb table 和数据迁移以创建新的密钥结构,因为这可能会导致停机。
您无法更新 DynamoDB 中的主键。来自 docs:
You cannot use UpdateItem to update any primary key attributes. Instead, you will need to delete the item, and then use PutItem to create a new item with new attributes.
如果你想让数据可以被 _id
搜索到,你可以引入一个 secondary index 并且 _id
字段作为索引的分区键。
例如,假设您的数据如下所示:
如果您在 _id
上定义了二级索引,索引将如下所示(与上一个示例相同的数据,只是不同的逻辑视图):
DynamoDB 目前没有任何本机版本控制功能,因此您必须将其合并到您的数据模型中。幸运的是,网络上有很多关于此用例的讨论。 AWS 有一份 DynamoDB“最佳实践”文档,其中包括 example of versioning.