Include ATTR_MIGRATION_VERSION in update()

This commit is contained in:
Chris Eager
2021-04-21 13:51:12 -05:00
committed by Chris Eager
parent 53e6f419b6
commit abafa2ccac
2 changed files with 15 additions and 4 deletions

View File

@@ -177,11 +177,13 @@ public class AccountsDynamoDb extends AbstractDynamoDbStore implements AccountSt
updateItemRequest = new UpdateItemRequest()
.withTableName(accountsTable.getTableName())
.withKey(Map.of(KEY_ACCOUNT_UUID, new AttributeValue().withB(UUIDUtil.toByteBuffer(account.getUuid()))))
.withUpdateExpression("SET #data=:data")
.withUpdateExpression("SET #data = :data, #version = :version")
.withConditionExpression("attribute_exists(#number)")
.withExpressionAttributeNames(Map.of("#number", ATTR_ACCOUNT_E164,
"#data", ATTR_ACCOUNT_DATA))
.withExpressionAttributeValues(Map.of(":data", new AttributeValue().withB(ByteBuffer.wrap(SystemMapper.getMapper().writeValueAsBytes(account)))));
"#data", ATTR_ACCOUNT_DATA,
"#version", ATTR_MIGRATION_VERSION))
.withExpressionAttributeValues(Map.of(":data", new AttributeValue().withB(ByteBuffer.wrap(SystemMapper.getMapper().writeValueAsBytes(account))),
":version", new AttributeValue().withN(String.valueOf(account.getDynamoDbMigrationVersion()))));
} catch (JsonProcessingException e) {
throw new IllegalArgumentException(e);