Image for post
Image for post

When you work with frameworks such as ASP.NET or Django, ORM (Entity Framework, Django ORM) magically creates migration, and with DynamoDB, it may seem strange that you need to write migrations by yourself. But it is the price of using NoSQL and rejecting ORMs, but don’t worry, managing migrations by yourself isn’t that scary.

The first step is to check which tables were created and which ones were deleted. In order to do this, I compare DynamoDB tables' names with my list of tables parameters. After that, I execute operations that will delete and create tables if needed.

prepare tables

In order to see which migration was executed last time, I have the table with migration info. It looks like this:

Image for post
Image for post
migration item

All my migrations are just array of asynchronous functions which perform operations on tables items.

In order to run these migrations, I take the index of the last executed migration and run all migrations, starting from this index. If there was no migration item in the management table it means that tables are empty and there is no need for migrations execution.

Finally, you will have a script for database preparation. And you can run it automatically before deployment.

final script

Reach the next level of focus and productivity with increaser.org.

Image for post
Image for post
Increaser

Written by

Software engineer, creator of increaser.org. More at geekrodion.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store