Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB schema updates with AWS Amplify

According to the AWS Amplify documentation:

  • "objects annotated with @model are stored in Amazon DynamoDB";
  • "a single @model directive configures ... an Amazon DynamoDB table"; and
  • one can "push updated changes with amplify push".

It seems clear that amplify push creates a DynamoDB table for each @model.

My questions relate to schema updates:

  • I imagine that adding/removing a model or adding/removing a field in a model works by updating the schema document and then running amplify push. Is that right?

  • How does one rename a model or a field? How would amplify push know to rename vs. drop the old and add the new?

  • How does one implement a migration that requires some business logic, e.g., to update the contents of existing rows? Doing this without Amplify has already been addressed but it is unclear whether that would conflict with something that amplify push might try to do.

like image 336
kkurian Avatar asked Nov 19 '18 10:11

kkurian


People also ask

Does DynamoDB support schema changes?

Key-value and document data modelsThis enables DynamoDB to have a flexible schema, so each row can have any number of columns at any point in time. This allows you to easily adapt the tables as your business requirements change, without having to redefine the table schema as you would in relational databases.

Does AWS amplify use DynamoDB?

Using the CLI, developers can automatically create tables representing the schema defined at the application level on DynamoDB. Although DynamoDB is Amplify DataStore's default database solution, developers can create AWS AppSync resolvers to use different purpose-built database offerings provided by AWS.

Are DynamoDB updates Atomic?

DynamoDB provides four operations for basic create, read, update, and delete (CRUD) functionality. All these operations are atomic.


1 Answers

DynamoDB is schema-less, and doesn't care about your application schema as long as you don't try to change its hash key or range key

Therefore, nothing really happens on the datastore side. If you drop a key and add a new one in your schema, then your application will start to search and write data to the new key. Old key will simply be ignored from now on, but existing data will be kept in the datastore.

If you want to rename a key, then you would have to migrate the data by yourself through mass update on the table. There are many ways to do it, the simpliest one being scaning the table and performing updates on found items.

like image 69
aherve Avatar answered Nov 09 '22 09:11

aherve