在 AWS Amplify 中更改 GraphQL 架构时如何防止丢失生产数据?

问题描述 投票:0回答:2

在我的 AWS Amplify 项目中,我使用带有多个

@model
指令的 GraphQL API。因此,Amplify 在我的 AWS 后端生成了多个 DynamoDB 表。现在,当删除这样的
@model
或重命名它时,旧的 DynamoDB 表将被永久删除,其中包含的所有数据

如何避免这种情况,避免生产数据出错?

amazon-web-services graphql amazon-dynamodb aws-amplify aws-amplify-cli
2个回答
1
投票

要防止删除 DynamoDB 表,您可以将

DeletionPolicy
设置为
Retain
。不幸的是,Amplify 默认情况下不会这样做。

因此,您可以像这样使用 自定义 GraphQL 指令

@retain

  1. 安装变压器:
    npm install --save graphql-retain-transformer
  2. 编辑
    amplify/backend/api/<YOUR_API>/transform.conf.json
    并将
    "graphql-retain-transformer"
    附加到变压器字段:
"transformers": [
    "graphql-retain-transformer"
]
  1. 在您的
    schema.graphql
    文件中,将
    @retain
    指令附加到您想要为其激活保留删除策略的所有
    @model
    类型:
type Todo @model @retain {
  id: ID!
  title: String!
  description: String
}

自定义指令的GitHub存储库:https://github.com/flogy/graphql-retain-transformer(如果您喜欢,请留下⭐️🙂)

有关它的更详细的博客文章:https://react-freelancer.ch/blog/amplify-retain-dynamodb-tables


0
投票

这个库仍然可行吗,因为当我按照 github read me 通过 npm 安装它时,它出错了:

npm WARN deprecated [email protected]: The library contains critical security issues and should not be used for production! The maintenance of the project has been discontinued. Consider migrating your code to isolated-vm.
© www.soinside.com 2019 - 2024. All rights reserved.