Reputation: 429
I have a schema.graphql file in my React project.
When I update the schema and remove attributes, the dynamoDB table doesn't change. The new fields don't appear and the old ones that I removed remain.
I've tried to amplify push
several times but nothing changes.
What can I do to solve this or sync the table?
Thanks.
Upvotes: 1
Views: 1070
Reputation: 14796
Currently AWS Amplify doesn't support automatic migration of data. What you are seeing is to be expected with a schemaless NoSQL table. Quoting the docs:
Tables are the fundamental data structures in relational databases and in DynamoDB. A relational database management system (RDBMS) requires you to define the table's schema when you create it. In contrast, DynamoDB tables are schemaless—other than the primary key, you do not need to define any attributes or data types at table creation time.
You need to stop thinking of the resources that Amplify generates for you as a RDBMS and start thinking of it in terms of a NoSQL database. Amplify uses a clever trick to let you create relational-ish data schemes. I recommend you read the core components part of the DynamoDB docs to understand what primary and (global / local) secondary indexes are. Afterwards, watch this video which explains how Amplify creates the relations between tables. (BTW, most well designed DynamoDB backends have only a single table - so only a single @model
directive and no @connection
directives.)
What is going on is if you do amplify push
your changes get applied to the AppSync GraphQL endpoint. (You may want to verify that in your console). But, the existing data in the DynamoDB stays the same. If you create new data it will follow the schema of your schema.graphql
file.
Upvotes: 1