Record Instance Update

Open
#59 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
aws, ruby
Domain
databases

Research direction

Start at ItemOperations#_perform_save and read issue #58 for the GSI behavior that update currently misses. Compare the existing save and update paths, then define upsert's expected handling of dirty columns, record creation, and the conditional-write race; it is done when the requested MyRecord example updates the dynamic GSI correctly.

Written by the indexing model from the issue text.

Description

feature-request

Right now save (or save!) encapsulates the selection between a put and an update, with the ability to force put. I recently wanted a "find or create" method, and naively did:

record = MyRecord.find(key: 123)
record ||= MyRecord.new(key: 123)
...
record.save! #=> Conditional write exception

I end up receiving the conditional write exception because some other process is trying to create the same record.

To fix this, I moved to using an update:

MyRecord.update(key: 123, value: 'some new data')

However, we have a GSI which is dynamically generated from the values which update never takes into account (see issue #58). Thus, the preferred solution would be:

MyRecord.new(key: 123, value: 'some new data').upsert!

To achieve this I copied the else statement from ItemOperations#_perform_save which builds an update request for dirty columns and creates the record if it does not already exist; hence upsert.

Dominant language
Ruby
Stars
318
Forks
44
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aws/aws-record-ruby

All issues in aws/aws-record-ruby

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.