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.
Create and Delete Tables
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.
In order to see which migration was executed last time, I have the table with migration info. It looks like this:
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.
Reach the next level of focus and productivity with increaser.org.