[英]How to prevent losing production data when changing my GraphQL schema in AWS Amplify?
In my AWS Amplify project I am using a GraphQL API with several @model
directives.在我的 AWS Amplify 项目中,我使用带有多个
@model
指令的 GraphQL API。 Therefore, Amplify generated multiple DynamoDB tables in my AWS backend.因此,Amplify 在我的 AWS 后端生成了多个 DynamoDB 表。 Now, when removing such a
@model
or renaming it, the old DynamoDB table will be permanently deleted with all the contained data !现在,当删除这样的
@model
或重命名它时,旧的 DynamoDB 表将被永久删除,其中包含所有数据!
How can this be prevented to avoid production data by mistake?如何防止这种情况发生,以避免错误地避免生产数据?
To prevent your DynamoDB tables from being deleted you can set the DeletionPolicy
to Retain
.为了防止您的 DynamoDB 表被删除,您可以将
DeletionPolicy
设置为Retain
。 Unfortunately, Amplify does not do this by default.不幸的是,默认情况下 Amplify 不会这样做。
Therefore, you can use the custom GraphQL directive @retain
like this:因此,您可以像这样使用自定义 GraphQL 指令
@retain
:
npm install --save graphql-retain-transformer
.npm install --save graphql-retain-transformer
。amplify/backend/api/<YOUR_API>/transform.conf.json
and append "graphql-retain-transformer"
to the transformers field:amplify/backend/api/<YOUR_API>/transform.conf.json
并将"graphql-retain-transformer"
附加到转换器字段:"transformers": [
"graphql-retain-transformer"
]
schema.graphql
file, append the @retain
directive to all the @model
types that you want to activate the Retain Deletion Policy for:schema.graphql
文件中,将@retain
指令附加到您想要激活保留删除策略的所有@model
类型:type Todo @model @retain {
id: ID!
title: String!
description: String
}
GitHub repository of the custom directive: https://github.com/flogy/graphql-retain-transformer (please leave a ⭐️ if you like it 🙂)自定义指令的 GitHub 仓库: https : //github.com/flogy/graphql-retain-transformer (喜欢请留下一个⭐️🙂)
A more detailed blog post about it:https://react-freelancer.ch/blog/amplify-retain-dynamodb-tables关于它的更详细的博客文章:https ://react-freelancer.ch/blog/amplify-retain-dynamodb-tables
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.