Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB Table Modeling. Soft delete solution

Hello stackoverflow community. I am trying to organize soft delete solution for dynamodb.

If you have though on the same problem and find out any solution, please share in comment.

It involves thinking about: List items (isDeleted: false or 0), and use limit of results.

like image 663
Ihor Fito Avatar asked Sep 09 '26 10:09

Ihor Fito


1 Answers

We need to create RANGE index, for example Number with any data (0/1).

In my case it is "isActive = 1" for not deleted items.

Then we do query or scan with that IndexName.

In order to make item soft deleted, we need to remove attribute "isActive"

DynamoDB Scan and Query with Index

Official Best Practice: Take Advantage of Sparse Indexes - there is described our case.

In order to remove attribute use this example:

const params = {
      TableName: this.TABLE,
      Key: {
        _id: id
      },
      UpdateExpression: 'REMOVE isActive',
      ReturnValues: 'ALL_NEW'
    }
    return dynamodb.update(params).promise()
      .then((data) => {
        if (data) {
          return data.Attributes
        }
        return null
      })
like image 82
Ihor Fito Avatar answered Sep 12 '26 04:09

Ihor Fito



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!