PynamoDB icon indicating copy to clipboard operation
PynamoDB copied to clipboard

Migration from LegacyBooleanAttribute to BooleanAttribute, a request to check idea.

Open vo-va opened this issue 4 years ago • 2 comments

Hi, I am still using pynamodb 3.4.1 because I have LegacyBooleanAttribute and want to do a migration to the new pynamodb version and to new Boolean attributes. The script for migration that is available in 3.x version assumes that the application will not work during migration. And downtime for me is very undesirable.

So I had the next idea. Change LegacyBooleanAttribute in such way so it will be able to read data in the old and in the new format, but will write only in the new format. Start the application with patched pynamodb in that way, and do the migration. After the migration is complete switch the application to the new version of pynamodb that used only BooleanAttribute. I've checked my code, fields that are LegacyBooleanAttribute are not used in queries with conditions so I don't need to deal with fixing syntax for that, therefore I guess my patch will be relatively safe. But maybe I am missing something, can you say if my assumption about the patch is correct or wrong? Patch here https://github.com/vo-va/PynamoDB/commit/9e311344b42c2acc1f9458ba9b02db9c2fc371fc

vo-va avatar Dec 06 '21 10:12 vo-va

I'm afk now but the approach I'd probably take is to create two attributes:

NumberAttribute(null=True, attr_name="my_legacy_bool")
BooleanAttribute(null=True, attr_name="my_legacy_bool")
  1. Make a change where your application checks them both and modifies only the first one, and deploy it
  2. Make a change where your application modifies the second one instead of first one, and deploy
  3. Modify all items
  4. Remove first attribute and deploy

ikonst avatar Dec 11 '21 02:12 ikonst

@ikonst Hi, thank you for the feedback, and sorry for the late response. Can I ask you to clarify about attr_name values? I think they should be different or the library will override one attribute with the value of another. At least this is what I see in my tests.

And probably the steps should be next.

  • Update app that will have additional attr in the model. This version writes in both attributes but reads only from the legacy.
  • Run migration script that will read the value from legacy and write data to new attr.

After migration data should be synced and because the code writes in both places even new data will be fine

  • Update the app to read from new attributes but write in both.
  • Test that everything is working
  • Update the app to remove the code that is related to the old legacy attribute.

vo-va avatar May 20 '22 19:05 vo-va