amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

amplify push creating rather than updating a table

Open aehringer opened this issue 7 years ago • 11 comments

** Which Category is your question related to? ** graphql-transform, cloudformation, amplify push

** What AWS Services are you utilizing? ** dynamodb, amplify api

** Provide additional details e.g. code snippets ** I'm getting this failure after I try to push an updated api schema with just one extra (empty) line. I see that it is failing because it is trying to create a table that already exists. Why is it not just updating the table, as it does with all the other tables I have? Nothing in this table is being modified at all.

CREATE_IN_PROGRESS SavedRestaurantTable AWS::DynamoDB::Table Wed Jun 12 2019 16:31:26 GMT+0200 (CEST)
CREATE_FAILED SavedRestaurantTable AWS::DynamoDB::Table Wed Jun 12 2019 16:31:26 GMT+0200 (CEST) SavedRestaurant-muz7cgqce5hmtkneh5jqg242f4 already exists in stack arn:aws:cloudformation:us-east-1::stack/reco--apireco--SavedRestaurant-/*********************************** UPDATE_ROLLBACK_IN_PROGRESS reco--apireco--Restaurant-************ AWS::CloudFormation::Stack Wed Jun 12 2019 16:31:29 GMT+0200 (CEST) The following resource(s) failed to create: [SavedRestaurantTable].

aehringer avatar Jun 12 '19 14:06 aehringer

@aehringer could you share what change you made to your schema. A minimal repro repo would make it a lot faster for us to diagnose the issue

yuth avatar Jun 12 '19 17:06 yuth

I added an empty line. Before:

type User 
	@model 
	@searchable 
	@versioned
{
	id: ID!
	savedPlaces: [SavedRestaurant] @connection(name: "User_SavedRestaurant")
}

type SavedRestaurant @model(queries: null) {
	id: ID!
	user: User! @connection(name:"User_SavedRestaurant")
	restaurant: Restaurant! @connection
}

type Restaurant 
	@model 
	@searchable
	@versioned
{
	id: ID!
	name: String!
	googleId: String
	location: String
}

amplify status: Screen Shot 2019-06-12 at 8 33 22 PM

After:

type User 
	@model 
	@searchable 
	@versioned
{
	id: ID!
	savedPlaces: [SavedRestaurant] @connection(name: "User_SavedRestaurant")
}

type SavedRestaurant @model(queries: null) {
	id: ID!
	user: User! @connection(name:"User_SavedRestaurant")
	restaurant: Restaurant! @connection
}

type Restaurant 
	@model 
	@searchable
	@versioned
{
	id: ID!
	name: String!
	googleId: String
	location: String

}

^empty line after "location: String"

amplify status: Screen Shot 2019-06-12 at 8 33 52 PM

aehringer avatar Jun 12 '19 18:06 aehringer

More info: My AppSync console shows that the mutations for updating/deleting/creating a SavedRestaurant exist. It seems amplify push did some damage to something because now none of these work in my app. When attempting to create a SavedRestaurant, this is what is returned (using the createSavedRestaurant from src/mutations): Object { "data": Object { "createSavedRestaurant": null, }, }

My DynamoDB console shows that a SavedRestaurant table does exist.

I also tried deleting SavedRestaurant entirely from my schema and pushing, but I could not delete the resource because of the connection that is using it. I cannot delete the connection because of my original issue.

I also checked the stacks folder in amplify/backend/api//build/stacks, and all the models of my schema appear there except for SavedRestaurant. So it is not being created during "amplify push"?

aehringer avatar Jun 12 '19 20:06 aehringer

@aehringer Thank you for the information. It looks like this may be related to an issue with an internal mechanism that splits resources into nested stacks. The issue arises when types share a common part of their name e.g. Restaurant and SavedRestaurant. I have started working on a fix for the issue with the internal mapping but am also going to need to expose an interface that mitigates the issue for any existing environments.

mikeparisstuff avatar Jun 13 '19 17:06 mikeparisstuff

@mikeparisstuff ok, do you have an idea of the timeframe for that? Thanks!

aehringer avatar Jun 13 '19 18:06 aehringer

@aehringer Work is current under way and I am aiming for the end of the week to have the change and appropriate testing in place. Can you please provide a bit more information about what change you were making when the issue first started by sharing the schema before and after the problematic push?

Also if you are blocked you can generate templates using ampify api gql-compile and fix any templates created by the transform libraries (in build/) and then push using amplify push --no-gql-override flag as outlined here https://github.com/aws-amplify/amplify-cli#commands-summary.

mikeparisstuff avatar Jun 17 '19 18:06 mikeparisstuff

@mikeparisstuff The change I made to the schema before the problematic push was adding SavedRestaurant to the schema. I ended up removing the api and creating adding a new one with SavedPlaces rather than SavedRestaurant (before I saw your message) and the problem was gone -- so I do think the problem was the naming of the models.

aehringer avatar Jun 20 '19 13:06 aehringer

@aehringer Yes the problem was related to the naming of the models. A fix is being prepped in PR to address this moving forward and we will also be adding a small check that allows APIs created before the issue was fixed to continue working as normal so others experiencing this do not need to delete & replace anything.

mikeparisstuff avatar Jun 24 '19 22:06 mikeparisstuff

@aehringer We merged a fix for this in the latest version of the CLI. If you're still this issue please feel free to comment on this thread and we'll re-open this issue.

kaustavghosh06 avatar Jul 03 '19 06:07 kaustavghosh06

Also if you are blocked you can generate templates using ampify api gql-compile and fix any templates created by the transform libraries (in build/) and then push using amplify push --no-gql-override flag as outlined here https://github.com/aws-amplify/amplify-cli#commands-summary.

@mikeparisstuff @kaustavghosh06 how do you suggest to "fix any templates created by the transform libraries in build/"? I've run into this same issue on the latest CLI and am not sure what I'm looking for to fix it.

davekiss avatar Jul 04 '19 11:07 davekiss

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

github-actions[bot] avatar May 27 '21 06:05 github-actions[bot]