简体   繁体   English

使用 AWS Amplify 更新 DynamoDB 架构

[英]DynamoDB schema updates with AWS Amplify

According to the AWS Amplify documentation:根据 AWS Amplify 文档:

It seems clear that amplify push creates a DynamoDB table for each @model.很明显, amplify push为每个@model 创建了一个 DynamoDB 表。

My questions relate to schema updates:我的问题与架构更新有关:

  • I imagine that adding/removing a model or adding/removing a field in a model works by updating the schema document and then running amplify push .我想象添加/删除 model 或添加/删除 model 中的字段是通过更新模式文档然后运行amplify push来工作的。 Is that right?是对的吗?

  • How does one rename a model or a field?如何重命名 model 或字段? How would amplify push know to rename vs. drop the old and add the new? amplify push如何知道重命名与删除旧的并添加新的?

  • How does one implement a migration that requires some business logic, eg, to update the contents of existing rows?如何实现需要一些业务逻辑的迁移,例如,更新现有行的内容? Doing this without Amplify has already been addressed but it is unclear whether that would conflict with something that amplify push might try to do.在没有 Amplify 的情况下执行此操作已经得到解决,但尚不清楚这是否会与amplify push可能尝试做的事情发生冲突。

DynamoDB is schema-less, and doesn't care about your application schema as long as you don't try to change its hash key or range key DynamoDB 是无架构的,只要您不尝试更改其hash 键范围键,它就不会关心您的应用程序架构

Therefore, nothing really happens on the datastore side.因此,数据存储端实际上什么也没有发生。 If you drop a key and add a new one in your schema, then your application will start to search and write data to the new key.如果您删除一个键并在您的架构中添加一个新键,那么您的应用程序将开始搜索并将数据写入新键。 Old key will simply be ignored from now on, but existing data will be kept in the datastore.从现在开始将简单地忽略旧密钥,但现有数据将保留在数据存储中。

If you want to rename a key, then you would have to migrate the data by yourself through mass update on the table.如果你想重命名一个键,那么你必须自己通过对表进行批量更新来迁移数据。 There are many ways to do it, the simpliest one being scaning the table and performing updates on found items.有很多方法可以做到这一点,最简单的方法是扫描表格并对找到的项目执行更新。

你有没有试过用这个编译模式:

amplify api gql-compile

Have you tried你有没有尝试过

amplify codegen models

before doing the在做之前

amplify push

after?后?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM