aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 79 forks source link

batch / bulk update pre-existing items or add new items to a data model #2620

Open TamsynJennifer4 opened 5 months ago

TamsynJennifer4 commented 5 months ago

Environment information

System:
  OS: macOS 14.0
  CPU: (10) arm64 Apple M1 Pro
  Memory: 180.89 MB / 32.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
  Yarn: 1.22.22 - ~/.nvm/versions/node/v18.16.0/bin/yarn
  npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/backend: 1.0.2
  @aws-amplify/backend-cli: 1.0.3
  aws-amplify: 6.3.4
  aws-cdk: 2.143.1
  aws-cdk-lib: 2.143.1
  typescript: 5.4.5
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Description

I have setup a data backend running in production and I am now updating a modal, say:

 User: a
    .model({
      id: a.id().required(),
      name: a.string(),
    })
    .authorization((allow) => [allow.owner()]),

I wish to add a new field to that model, say isVerifed which will be a boolean. For all current users this field will not exist and I will need to update those users to be true. How is it best to make this change? Will amplify-backend provide utils for this such cases to ensure that the data meets the scheme shape I already have. There are obviously a few ways one could try script this or attempt to handle migrations but none feel robust.

Is amplify developing an API for this or what are the best practises in handling these changes?

ykethan commented 5 months ago

Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂

AnilMaktala commented 5 months ago

Hey @TamsynJennifer4, Thank you for bringing this to our attention. Unfortunately, there is no built-in feature for performing bulk updates in this case. After adding the property to the schema, you can update the field by writing a one-time Lambda function to retrieve the list of users and update them in a loop.

TamsynJennifer4 commented 5 months ago

Thanks for the information. Is this a road-map feature for the API? I'm sure there are hundreds of teams running migrations on a daily basis and a simple API to handle this would greatly benefit the community.