Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete unused GraphQl model #9744

Closed
Lasim opened this issue Feb 11, 2022 · 2 comments
Closed

Delete unused GraphQl model #9744

Lasim opened this issue Feb 11, 2022 · 2 comments
Labels
duplicate If marked with duplicate, issue will be closed & original will be added for traceability question General question

Comments

@Lasim
Copy link

Lasim commented Feb 11, 2022

Which Category is your question related to?

  • api-graphql
  • Build settings

Amplify CLI Version
7.6.19

What AWS Services are you utilizing?
AppSync / DynamoDB

Provide additional details e.g. code snippets. Be sure to remove any sensitive data.
I would like to delete an unused GraphQL model.
Locally it works fine with amplify push --allow-destructive-graphql-schema-updates

My question is how do I do that in Amplify "Build settings" in amplify.yaml?

My current amplify.yaml file for Backend:

version: 1
backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple

I've also tried adding the flag --allow-destructive-graphql-schema-updates to amplifyPush command but without success.

How should I modify my Build Settings amplify.yaml so I can delete a @model in AppSync?

Thank you all for your time and effort.

Amplify (AWS Console) error message:

...
2022-02-11T00:08:16.537Z [WARNING]: ✔ Initialized provider successfully.
2022-02-11T00:08:18.164Z [WARNING]: ✖ An error occurred when pushing the resources to the cloud
2022-02-11T00:08:18.168Z [WARNING]: ✖ There was an error initializing your environment.
2022-02-11T00:08:18.172Z [INFO]: �[0mDestructiveMigrationError: Removing a model from the GraphQL schema will also remove the underlying DynamoDB table.�[0m
                                 �[0mThis update will remove table(s) [ProductTable, ShopTable]�[0m
                                 �[0mALL EXISTING DATA IN THESE TABLES WILL BE LOST!�[0m
                                 �[0mIf this is intended, rerun the command with '--allow-destructive-graphql-schema-updates'.�[0m
                                 �[0m    at cantRemoveTableAfterCreation (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/graphql-transformer-core/src/util/sanity-check.ts:422:11)�[0m
                                 �[0m    at sanityCheckDiffs (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/graphql-transformer-core/src/util/sanity-check.ts:59:9)�[0m
                                 �[0m    at sanityCheckProject (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/graphql-transformer-core/src/util/sanity-check.ts:41:21)�[0m
                                 �[0m    at GraphQLSanityCheck.validate (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/graphql-transformer/sanity-check.ts:17:5)�[0m
                                 �[0m    at buildAPIProject (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/graphql-transformer/transform-graphql-schema.ts:529:5)�[0m
                                 �[0m    at transformGraphQLSchema (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/graphql-transformer/transform-graphql-schema.ts:394:29)�[0m
                                 �[0m    at Object.run (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/push-resources.ts:166:5) {�[0m
                                 �[0m  removedModels: [ 'ProductTable', 'ShopTable' ],�[0m
                                 �[0m  replacedModels: [],�[0m
                                 �[0m  toString: [Function (anonymous)]�[0m
                                 �[0m}�[0m
2022-02-11T00:08:18.201Z [ERROR]: !!! Build failed
2022-02-11T00:08:18.202Z [ERROR]: !!! Non-Zero Exit Code detected
@Lasim Lasim added the question General question label Feb 11, 2022
@josefaidt josefaidt added the duplicate If marked with duplicate, issue will be closed & original will be added for traceability label Feb 11, 2022
@josefaidt
Copy link
Contributor

Hey @Lasim 👋 I've marked this as a duplicate of #9712. It is not recommended to use the CI/CD pipeline to perform this deletion. From the issue:

This warning is in place to prevent accidental deletion of data in production environments. If you are confident that you want to delete the table(s) then it is fine to run amplify push with --allow-destructive-graphql-schema-updates. However, I would not recommend setting the flag automatically permanently.

@meredian
Copy link

@josefaidt Ticked is somewhat old, but still I'm getting here again and again.

We would like to run it with the cloud, especially as you're advising not to do :) The problem is that it just doesn't work. Build pipeline, exactly as topic starter's, does not use amplify push, but uses amplifyPush. And that one ignores any setting for applying desctructive change - both ENV and flag.

How desperate we got:

version: 1
backend:
  phases:
    preBuild:
      commands:
      - npm ci
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - envCache --set stackInfo ""
        - AMPLIFY_DESTRUCTIVE_UPDATES=true amplifyPush --allow-destructive-graphql-schema-updates --force

Result:

2024-05-15T10:30:17.273Z [INFO]: # Executing command: AMPLIFY_DESTRUCTIVE_UPDATES=true amplifyPush --allow-destructive-graphql-schema-updates --force
...
2024-05-15T10:30:46.861Z [WARNING]: ✖ There was an error initializing your environment.
2024-05-15T10:30:46.866Z [INFO]: 🛑 Removing a model from the GraphQL schema will also remove the underlying DynamoDB table.
This update will remove table(s) [ActionTable, MessageTable, ReminderTable]
ALL EXISTING DATA IN THESE TABLES WILL BE LOST!
If this is intended, rerun the command with '--allow-destructive-graphql-schema-updates'.
Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

So, not much success 🥲 I'm wandering what's actually happens, line by line, but it's obscured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate If marked with duplicate, issue will be closed & original will be added for traceability question General question
Projects
None yet
Development

No branches or pull requests

4 participants